If a table "people" contains "name" (varchar) and "birthdate" (date) columns, how to find the oldest/youngest buddy?
+1
A:
SELECT * FROM buddies
WHERE birthdate = (
SELECT MAX(birthdate) FROM buddies
)
LIMIT 1;
bnaul
2010-09-12 17:06:40
+3
A:
SELECT name, birthdate FROM people ORDER BY birthdate ASC LIMIT 1
Note that if there are two or more people with the same birthdate only one will be returned.
Darin Dimitrov
2010-09-12 17:07:19
This is obviously the right way...for some reason I was conflating this with ORDER BY / GROUP BY, which doesn't always behave as nicely.
bnaul
2010-09-12 18:07:28
+1
A:
If you want to include ties
SELECT name
FROM people
where birthdate = (select max(birthdate) FROM people)
Martin Smith
2010-09-12 17:10:01