What does DESC do in SQL? [closed]
Emily Wong
I am confused as to what the word 'DESC' does? What is it's purpose? Could you maybe provide other example, thank you!
$result = mysql_query("SELECT *, ROUND(score/(1+(losses/wins))) AS performance FROM images ORDER BY ROUND(score/(1+(losses/wins))) DESC LIMIT 0,10");Edit: Realised this was a dumb question, should of used Google, I now know the answer stop attacking me guys I get it.
118 Answers
You can order your records in ascending or descending order. The default is ASCENDING, which is shortened to ASC in SQL syntax. The opposite is of course DESCENDING, which is shortened to DESC.
For example,
SELECT * FROM images ORDER BY id ASCThis might give:
id | image ---+----------- 1 | bird.png 2 | flower.pngHowever
SELECT * FROM images ORDER BY id DESC Would give:
id | image ---+----------- 2 | flower.png 1 | bird.png 1 DESC means descending.
if you have the letters A-Z in your database, and you sort them by ASC, it will go from A to Z.
ORDER BY DESC will sort them from Z to A.
same goes for 0-9, ascending and descending (for example).
It says "sort in descending order".
It is an optional keyword you can use with ORDER BY. (Sorting is done in ascending order by default.)
ORDER BY XXX DESC orders the results in descending order, as opposed to in ascending order ( ASC).
DESC sorts the resultset in descending order of the column specified, as opposed to ascending ASC which is the default
DESC is the explicit word to mention the Order to make it descending. A simple Order by will do it Ascending
DESC means sorting the selected data in descending order.
Example Syntax:
SELECT `name` from users where `name` LIKE '%Emmett%' ORDER BY `name`;This would yield/fetch names in Descending alphabetic order
It sorts records in descending order. Know more about Order by from here