I have a database of logos, 18K strong. Each logo has a score. I want to select the top 100 by score and display them from 100 to 1, not from 1 to 100.
My query is:
SELECT * FROM tbllogos WHERE status = 'live' ORDER BY score DESC LIMIT 100
which works fine for selecting the top 100, but the php WHILE loop then displays them from 1 to 100. I can't figure out how to swap the order so it displays 100 to 1. Changing DESC to ASC obviously isn't the answer as that selects the 100 with the lowest scores.
You can reverse the ordering by using DESC instead of ASC at the end of your query.
SQL Server REVERSE() Function The REVERSE() function reverses a string and returns the result.
Let us now implement the above query. mysql> SELECT * FROM ( -> SELECT * FROM Last10RecordsDemo ORDER BY id DESC LIMIT 10 -> )Var1 -> -> ORDER BY id ASC; The following is the output that displays the last 10 records. We can match both records with the help of the SELECT statement.
Use a subquery:
SELECT t.*
FROM (SELECT *
FROM tbllogos
WHERE status = 'live'
ORDER BY score DESC
LIMIT 100
) t
ORDER BY score ASC;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With