Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get latest date for each distinct entry?

43 views
Skip to first unread message

Plantky

unread,
Jan 18, 2008, 9:55:03 AM1/18/08
to
Hi,

I have a table called "obs" with the following:

observation INT AUTO_INCREMENT,
morph VARCHAR,
date DATE,
plot VARCHAR,
number INT,
comment TEXT,
week VARCHAR

observation is the primary key, and morph is a foreign key.

How do I make a query such that I get all the latest observation
'dates' of every distinct 'morph'?

Captain Paralytic

unread,
Jan 18, 2008, 9:59:58 AM1/18/08
to

Search this group for "strawberry query"
Also read
http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html
(you want the LEFT JOIN example)

Luuk

unread,
Jan 18, 2008, 10:57:18 AM1/18/08
to

"Captain Paralytic" <paul_l...@yahoo.com> schreef in bericht
news:b39176b1-e71d-4439...@d21g2000prf.googlegroups.com...


why not do:
SELECT morph, max(date) date FROM obs GROUP BY morph


Rik Wasmus

unread,
Jan 18, 2008, 11:18:19 AM1/18/08
to

Could be done, but not if you want the field 'observation' in there too.
So either solution could be valid, depending on what the OP really needs.
--
Rik Wasmus

Plantky

unread,
Jan 18, 2008, 11:19:32 AM1/18/08
to
Thanks Luuk, it works!!
0 new messages