tags:

views:

53

answers:

3

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
+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
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
+1  A: 

If you want to include ties

SELECT name 
FROM people
where birthdate = (select max(birthdate) FROM people)
Martin Smith