-1

I'm trying to sort an employee table, but if salary of two employees is same, I want to sort them alphabetically. How do I do this. I want sort alphabetically only in case salaries are same.

Jay Dutt
  • 1
  • 3
  • 1
    You can specify multiple columns to order by, and they are treated in order. i.e. `ORDER BY Salary, Name`, will sort first by salary, then by name – GarethD Feb 09 '22 at 14:17
  • 2
    `ORDER BY salary, name` – Luuk Feb 09 '22 at 14:17
  • 1
    You can have as many terms as you like in an order by so I don't see your problem. Please publish sample data and expected outcome as text together with any code you have and problems encountered. – P.Salmon Feb 09 '22 at 14:17
  • I want to sort alphabetically only in case salaries are same. @P.Salmon – Jay Dutt Feb 09 '22 at 14:20
  • 2
    That is understood so still not seeing your problem..anyway closed as a duplicate.To reopen you would have to make a case for it. – P.Salmon Feb 09 '22 at 14:21
  • @JayDutt: Please show some example data (use [edit]). If you add a [mre], your question might be re-opened. – Luuk Feb 09 '22 at 14:22

1 Answers1

0

You just add the next column:

 SELECT * FROM employees ORDER BY salary, name;
  • I don't want to sort the whole table alphabetically. I want to sort only those alphabetically where salaries are same. – Jay Dutt Feb 09 '22 at 14:21
  • @jay dutt this code does not sort the whole table alphabetically it sorts the whole by salary in ascending order and within salary by name in ascending order is this not what you want? If not what do you want. – P.Salmon Feb 09 '22 at 14:32
  • @JayDutt This does exactly that. – Santiago Ivulich Feb 10 '22 at 12:49