i have a db with records with date (timestamp) i need to select 10 records for each day (there are many more per day) and order them by few columns...
how should that qu
If you just need ten rows — any ten rows, you don't care which, and there is no guarantee they're random, you can use the LIMIT
clause. Example:
SELECT whatever
FROM tablename
WHERE datecol = '2009-07-13'
LIMIT 10
That'll give you ten rows. Its up to MySQL which ten. You can use ORDER BY
or additional WHERE
items to pick a certain 10. For example, here is the most recent 10:
SELECT whatever
FROM tablename
WHERE datecol = '2009-07-13'
ORDER BY timecol DESC
LIMIT 10
LIMIT
is documented as part of the SELECT syntax.