order by multiple when columns sql code example
Example 1: multiple order by sql
ORDER BY column1 DESC, column2
Example 2: sql order by multiple columns
SELECT * FROM table_name ORDER BY col1 ASC; -- ASCending is default
SELECT * FROM table_name ORDER BY col1 DESC; -- DESCending
SELECT * FROM table_name ORDER BY col1 DESC, col2 ASC; -- col1 DESC then col2 ASC
Example 3: t-sql conditional order by multiple columns
SELECT * FROM dbo.Employee
ORDER BY
CASE WHEN Gender='Male' THEN EmployeeName END Desc,
CASE WHEN Gender='Female' THEN Country END ASC