rh71
No Lifer
(simplified to explain easier)
TABLE A: name, age
TABLE B: name, verifiedby, verifieddate
1 name can have multiple ages (recorded in TABLE A) and each time they are verified by a person and timestamped (hence the records in TABLE B).
My Resultset after join (to show you what data is being pulled):
SELECT a.name, a.age, b.verifiedby, b.verifieddate
FROM A LEFT JOIN B ON a.name = b.name
NAME - AGE - VERIFIEDBY - VERIFIEDDATE
Joe - 21 - Abraham - 1/14/05
Joe - 24 - Abraham - 5/15/08
Joe - 24 - Bob - 5/16/08
Carl - 12 - Bob - 3/11/07
Carl - 13 - Bob - 5/16/08
Carl - 13 - Abraham - 5/14/08
DESIRED Resultset (only the latest [max] entries for each name, Joe & Carl):
NAME - AGE - VERIFIEDBY - VERIFIEDDATE
Joe - 24 - Bob - 5/16/08
Carl - 13 - Bob - 5/16/08
What is the SQL for this DESIRED resultset? I tried using max(b.verifieddate) with group by but it doesn't work.
SELECT a.name, a.age, b.verifiedby, max(b.verifieddate)
FROM A LEFT JOIN B ON a.name = b.name
GROUP BY a.age, a.name, b.verifiedby
Instead, it just shows me all of them again, like the top resultset.
TABLE A: name, age
TABLE B: name, verifiedby, verifieddate
1 name can have multiple ages (recorded in TABLE A) and each time they are verified by a person and timestamped (hence the records in TABLE B).
My Resultset after join (to show you what data is being pulled):
SELECT a.name, a.age, b.verifiedby, b.verifieddate
FROM A LEFT JOIN B ON a.name = b.name
NAME - AGE - VERIFIEDBY - VERIFIEDDATE
Joe - 21 - Abraham - 1/14/05
Joe - 24 - Abraham - 5/15/08
Joe - 24 - Bob - 5/16/08
Carl - 12 - Bob - 3/11/07
Carl - 13 - Bob - 5/16/08
Carl - 13 - Abraham - 5/14/08
DESIRED Resultset (only the latest [max] entries for each name, Joe & Carl):
NAME - AGE - VERIFIEDBY - VERIFIEDDATE
Joe - 24 - Bob - 5/16/08
Carl - 13 - Bob - 5/16/08
What is the SQL for this DESIRED resultset? I tried using max(b.verifieddate) with group by but it doesn't work.
SELECT a.name, a.age, b.verifiedby, max(b.verifieddate)
FROM A LEFT JOIN B ON a.name = b.name
GROUP BY a.age, a.name, b.verifiedby
Instead, it just shows me all of them again, like the top resultset.