Is there a specific way to select the oldest (or two oldest) dates from a column in MySQL?
I imagine I would use the ordered by criterion.
First, create an aggregate query that has two fields: GroupID and RecordDate. Group by the GroupID field, and choose the "Min" option for the RecordDate, to return the earliest date for each query.
Answer: Use a nested query to find the earliest birthday. We can order by birthday and select the first one only. If there are two or more oldest people then only one of them will be returned.
MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't. Instead, you follow the standard date format and use the DATE_FORMAT function to format the date the way you want.
You can order by the date field in your database. For oldest:
SELECT * FROM table WHERE condition ORDER BY dateField ASC LIMIT 1
For two oldest:
SELECT * FROM table WHERE condition ORDER BY dateField ASC LIMIT 2
etc, etc, ...
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