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

    Jun 28, 2023 · After the ORDER BY keyword, add the name of the column by which you’d like to sort records first (in our example, salary). Then, after a comma, add the second column (in our example, last_name). You can modify the sorting order (ascending or …

  2. sql - How to order by column A and then by column B ... - Stack …

    Jan 15, 2022 · The ORDER BY clause causes the output rows to be sorted. The argument to ORDER BY is a list of expressions that are used as the key for the sort. The expressions do not have to be part of the result for a simple SELECT, but in a compound SELECT each sort expression must exactly match one of the result columns.

  3. sql server - Sort by Date in SQL - Stack Overflow

    Jun 1, 2011 · I don't have SQL Server handy so I'm not sure if it will be happy with a boolean in the ORDER BY clause though. If it doesn't like the boolean ORDER BY, then a CASE should do the trick: ORDER BY CASE WHEN DATEPART(month, resource_date) < DATEPART(month, GETDATE()) THEN 0 ELSE 1 END, DATEPART(month, resource_date)

  4. sql - How do I sort by a specific order - Stack Overflow

    Jan 3, 2012 · It is just a coincidence, the idea is to sort based on the ID only. This can be for several reasons. For example user-specified order, ordered by another resultset on another layer in the application than the database etc.

  5. Optimizing SQL queries by removing Sort operator in Execution plan

    May 15, 2011 · Often, a sort-operator can trivially be moved into the index, and, if only the first couple rows of the result set are fetched, can substantially reduce query cost, because the database no longer has to fetch all matching rows (and sort them all) to find the first ones, but can read the records in result set order, and stop once enough records ...

  6. Sorting in descending order in SQL - Stack Overflow

    Mar 6, 2018 · I have a table having customer name, and their 2 ids- id 1 and id 2. Id2 is distinct for all customers but id1 is same for some of them. I want to sort the table in descending order on the basis of id 1. SELECT * FROM table_name ORDER BY id1 DESC works fine but same id1 should be sorted in descending order on the basis of their id2 value.

  7. Custom Sorting in SQL order by clause? - Stack Overflow

    Oct 8, 2015 · But if a Z record is in the results, then it needs to be the first result in the query, but the rest of the records should be in "natural" sort order. For instance, if A C D are found, then the result should be

  8. Sorting by date & time in descending order? - Stack Overflow

    Jan 3, 2012 · all I want to display last 5 entered data for specific id. My sql query is, SELECT id, name, form_id, DATE(updated_at) as date FROM wp_frm_items WHERE user_id = 11 && form_id=9 ORDER BY updated_at DESC updated_at is DATETIME. It displays last 5 entry sort by date not by time. On same date then it is sorting alphabetically.

  9. Dynamic Sorting within SQL Stored Procedures - Stack Overflow

    I fetch the data into the C# with the initial sort order in the SQL order by clause, put that data in a DataView, cache it in a Session variable, and use it to build a page. When the user clicks on a column heading to sort (or page, or filter), I don't go back to the database.

  10. sql server - SQL - order by list order - Stack Overflow

    Jul 7, 2011 · E.g. (SQL Server) declare @T table (RecordID int,Position int) insert into @T (RecordID,Position) select 22,1 union all select 15,2 union all select 105,3 union all select 1,4 union all select 65,5 union all select 32,6 select * from Table t inner join @T t2 on t.RecordID = t2.RecordID order by t2.Position

Refresh