Let's say I have a table in MySQL DB with following columns
employee, status, work, start_date
Consider that start_date
column is date and time.
If I do
SELECT employee, status, work, start_date from table_name WHERE DATE(date) >= CURDATE()-10
this will give me records from Current date
- 10 days. In this case I might get 1 record to 100 records based on the data.
I need only 10 records based on date/time (e.g. if there are 10 employees that started to work today then I should get only today's records and not 10 days record)
How can I do that?
You mean you want the ten most recent entries? You can add an ORDER BY to set the order in which the results come back, and a LIMIT to reduce the total number of results.
SELECT employee, status, work, start_date from table_name
WHERE DATE(date) >= CURDATE()-10
ORDER BY date DESC
LIMIT 10