views:

406

answers:

2

Problem 2b goes as follows:

2b. For each subject show the first year that the prize was awarded.

nobel(yr, subject, winner)

My solution was this:
SELECT DISTINCT subject, yr
FROM nobel
ORDER BY yr ASC;

Why isn't this working?

+1  A: 

Your answer gets a row for every distinct combination of subject and year.

The correct answer GROUPS BY the subject, and gets the MIN year per subject.

Enough of a clue?

Ed Guiness
Oh. Yes that helps. Thanks.
Daddy Warbox
SELECT subject, min(yr)FROM nobelGROUP BY subject;
Ed Guiness
SELECT subject, MIN(yr) AS yr FROM nobel GROUP BY subject ORDER BY yr
Doug Currie
Heh you didn't need to. But thanks anyway.
Daddy Warbox
Wait... AS yr? I haven't read up on AS yet.
Daddy Warbox
"AS" names the column, so instead of some default like "Expr1" you get "yr"
Ed Guiness
Oh I see. That's helpful.
Daddy Warbox
A: 
SELECT subject, MIN(yr)
FROM nobel
GROUP BY subject;

Yay!

Daddy Warbox