How to sort by several columns with different order directions in SQL

I’m working on a database query and need help with ordering results. I want to sort my data using multiple fields at the same time, but each field needs to be sorted in a different direction.

For example, let’s say I have a table with employee data. I want to sort by salary in descending order (highest first) and then by hire_date in ascending order (oldest first). How do I write the ORDER BY clause to handle this?

Here’s a simple example of what I’m trying to achieve:

SELECT employee_name, salary, hire_date 
FROM staff_table 
ORDER BY salary DESC, hire_date ASC;

Is this the correct syntax? I want to make sure I’m doing this right because the ordering is really important for my reports.

hey iris! your syntax looks perfect - that’s exactly how you handle multiple column sorting with different directions. have you tested it with real data yet? results can be surprising if you’ve got lots of duplicate salary values. what patterns are you seeing in your employee data?

yep, that’s right! order matters a lot here - sql sorts left to right, so it’ll sort by salary first, then use hire_date to break ties. i’ve seen people put the less important column first and wonder why their results look off.

Your SQL syntax is spot on. ORDER BY works left to right - it’ll sort by salary descending first, then by hire_date ascending within each salary group. I’ve used this tons in financial reports when ranking products by revenue (high to low) and then launch date (old to new). Just watch out for NULL values - they show up first or last depending on your database. Add NULLS FIRST or NULLS LAST if you need to control where they appear.