How to Sort Data in SQL

Need your SQL results in a specific order?

Use ORDER BY.

How to Sort Data in SQL

Common options:

  • ASC sorts values in ascending order
  • DESC sorts values in descending order
  • Sort by one column
  • Sort by multiple columns
  • Combine sorting with WHERE

Without ORDER BY, the database does not guarantee the order of returned rows.

If order matters, ask the database to order the results.

How to Delete Data from SQL

Need to remove data from a database?

Use DELETE.

How to Delete Data from SQL

Common examples:

  • DELETE removes rows
  • WHERE specifies which rows
  • No WHERE means all rows
  • Transactions help protect changes
  • ROLLBACK helps when something goes wrong

Before executing a DELETE, make sure your WHERE condition selects the rows you want to remove.

Stack Overflow Introduces Premium Feature That Automatically Closes Your Question Before You Post It

Stack Overflow Introduces Premium Feature That Automatically Closes Your Question Before You Post It

Stack Overflow unveiled a new premium feature called Predictive Closure™, designed to improve efficiency for both moderators and developers.

Instead of waiting for the community to close a question as a duplicate, unclear, or opinion-based, the platform now performs the action instantly.

"We've reduced the average time to closure from 14 minutes to 0.2 seconds," a spokesperson said.

The feature also displays the traditional response:

"This question has already been asked."

When users click the suggested duplicate, they are redirected to a post from 2013 discussing a completely different programming language.

Early adopters praised the feature.

"Now I know my question was wrong before I even finish typing it."

Stack Overflow says the next release will automatically recommend asking ChatGPT instead, saving everyone even more time. 😄

How to Create a Background Job

Need to execute work outside an HTTP request?

Use a background service.

How to Create a Background Job

Common options:

  • BackgroundService
  • IHostedService
  • Worker Service
  • Hangfire
  • Quartz.NET

Background services are useful for scheduled tasks, message processing, and long-running operations.

How to Read Configuration in ASP.NET Core

Need to access application settings?

Use IConfiguration

Common configuration sources:

  • appsettings.json
  • Environment variables
  • User Secrets
  • Azure Key Vault
  • Command-line arguments

ASP.NET Core automatically combines multiple configuration providers into a single configuration object.

How to Read Configuration in ASP.NET Core

How to Handle Errors in ASP.NET Core

Need to return a proper response when something goes wrong?

Use exception handling middleware.

How to Handle Errors in ASP.NET Core

Common approaches:

  • UseExceptionHandler()
  • Custom exception middleware
  • Return appropriate HTTP status codes
  • Log unexpected exceptions
  • Avoid exposing internal details

Centralized exception handling helps keep API responses consistent across your application.

How to Improve Code Quality

Common techniques:

  • Remove unused code
  • Use better names
  • Reduce duplication
  • Simplify logic
  • Fix bugs

Code quality often improves after these changes.

How to Build a SQL Query

Need to retrieve data from a database?

A typical SQL query consists of these clauses:

  • SELECT to choose columns
  • FROM to specify the table
  • JOIN to combine related tables
  • WHERE to filter rows
  • GROUP BY to group results
  • HAVING to filter groups
  • ORDER BY to sort data
  • OFFSET / FETCH or LIMIT to paginate

Not every query needs every clause, but this is the structure you'll see in most SQL statements.

How to Build a SQL Query

Understanding what each clause does makes reading and writing SQL much easier.

How to Execute Code Before Every Request

Need to run logic for every incoming HTTP request?

Use ASP.NET Core middleware.

Common middleware scenarios:

  • Logging requests
  • Handling exceptions
  • Authentication
  • Authorization
  • Adding custom headers
  • Response compression

Middleware executes in the order you register it in the pipeline.

Each middleware can inspect the request, perform work, and pass execution to the next middleware.

How middleware works in .NET

How to Secure an ASP.NET Core Endpoint

Want to protect an API endpoint?

How to Secure an ASP.NET Core Endpoint

Add the [Authorize] attribute.

Common authorization options:

  • [Authorize]
  • [Authorize(Roles = "Admin")]
  • [Authorize(Policy = "EmployeeOnly")]
  • [AllowAnonymous] for public endpoints
  • Configure authentication before using authorization

Protected endpoints require authenticated users before your action executes.

Public endpoints without [Authorize] are accessible without authentication.

How do you organize authorization in your APIs?