Hi Stackoverflow users,
I'm currently working on a small website and I need a SQL query that selects 3 rows with the most 'Likes'. I've tried using max and top 3 but nothing seem to work for me. I would appreciate some help from you guys! Thanks in advance.

Using TOP won't work with MySQL, because that is SQL Server (or maybe Access) syntax. You probably want LIMIT here:
SELECT *
FROM yourTable
ORDER BY Likes DESC
LIMIT 3;
We could have also used:
LIMIT 3, OFFSET 0; -- three records with no offset
LIMIT 0, 3 -- same as above
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