About 1,760,000 results
Open links in new tab
  1. sorting - SQL multiple column ordering - Stack Overflow

    Jun 28, 2023 · If you want to use ascending (low to high) order, you can use the ASC keyword; this keyword is optional, though, as that is the default order when none is specified. If you want to use descending order, put the DESC keyword after the appropriate column (in the example, we used descending order for the salary column).

  2. MySQL ORDER BY multiple column ASC and DESC - Stack Overflow

    Jul 2, 2014 · SELECT users.username, avg(scores.point), avg(scores.avg_time) FROM scores, users WHERE scores.user_id = users.id GROUP BY users.username ORDER BY avg(scores.point) DESC, avg(scores.avg_time) LIMIT 0, 20 (this query to get each users average point and average avg_time by desc point, asc )avg_time

  3. SQL – Multiple Column Ordering - GeeksforGeeks

    Feb 7, 2025 · In this article, we will explain how to use the ORDER BY clause to sort data by one or more columns, demonstrate how to sort in both ascending and descending order, and explore techniques for sorting with multiple criteria to enhance query results.

  4. SQL ORDER BY Keyword - W3Schools

    The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

  5. sql - CASE Statement for Order By Clause with Multiple Columns …

    You can write multiple cases, even if they all have the same condition. ORDER BY CASE @OrderByColumn WHEN 1 THEN Forename END DESC, CASE @OrderByColumn WHEN 1 THEN Date END, CASE @OrderByColumn WHEN 1 THEN Location END, CASE @OrderByColumn WHEN 2 THEN Surname END ASC

  6. How to Order Results by Multiple Columns in SQL - Baeldung

    May 28, 2024 · Learn how to sort the results of an SQL query by multiple columns in the ORDER BY clause.

  7. CASE ORDER BY with multiple columns, and different sort options

    I am attempting to use a T-SQL CASE ORDER BY in a stored procedure where I am passed @OrderBy parameter as a TINYINT. @Orderby = 1 Then Date column should be ASC @Orderby = 2 Then Date column should be DESC

  8. sorting - Optimizing SQL Queries with Multiple Column Ordering: …

    Feb 18, 2025 · In SQL, when you want to sort your query results based on multiple criteria, you use the ORDER BY clause with multiple columns. This allows you to create a more granular and specific sorting order. Basic Syntax. SELECT column1, column2, ... FROM table_name. ORDER BY column1 ASC|DESC, column2 ASC|DESC, ...; Breakdown.

  9. ORDER BY Statement in SQL - ASC, DESC and multiple cols

    ORDER BY multiple columns. When we sort on multiple columns, SQL first sorts the result set based on the first column specified in the ORDER BY clause. If there are ties (i.e., values in the first column are the same), it then sorts based on the second column, and so on.

  10. How to Order By Two Columns in SQL? - LearnSQL.com

    Learn how to sort SQL results by two columns using ORDER BY. Step-by-step examples for sorting by salary and last name in ascending and descending order.

Refresh