Skip to content
Advertisement

Not able to arrange data in descending order using sql

enter image description here

I have created the above table on SQL workbench and trying to run a very basic query of giving the data in desc order according to salary (code shown below along with output) however I am not getting the correct output. Can anyone please help me with this

enter image description here

Advertisement

Answer

salary is obviously a text field. Either change it to an numeric type (integer or decimal would be appropriate), or CAST it in the query:

SELECT *
FROM employee
ORDER BY CAST(salary AS UNSIGNED) DESC
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement