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'?
|
|
0
|
|
|
|
Reply
|
Plantky
|
1/18/2008 2:55:03 PM |
|
On 18 Jan, 14:55, Plantky <ngokang...@gmail.com> wrote:
> 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'?
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)
|
|
0
|
|
|
|
Reply
|
Captain
|
1/18/2008 2:59:58 PM
|
|
"Captain Paralytic" <paul_lautman@yahoo.com> schreef in bericht
news:b39176b1-e71d-4439-b09e-c08d0bebfaf5@d21g2000prf.googlegroups.com...
> On 18 Jan, 14:55, Plantky <ngokang...@gmail.com> wrote:
>> 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'?
>
> 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)
why not do:
SELECT morph, max(date) date FROM obs GROUP BY morph
|
|
0
|
|
|
|
Reply
|
Luuk
|
1/18/2008 3:57:18 PM
|
|
On Fri, 18 Jan 2008 16:57:18 +0100, Luuk <luuk@invalid.lan> wrote:
> "Captain Paralytic" <paul_lautman@yahoo.com> schreef in bericht
> news:b39176b1-e71d-4439-b09e-c08d0bebfaf5@d21g2000prf.googlegroups.com...
>> On 18 Jan, 14:55, Plantky <ngokang...@gmail.com> wrote:
>>> 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'?
>>
>> 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)
>
>
> why not do:
> SELECT morph, max(date) date FROM obs GROUP BY morph
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
|
|
0
|
|
|
|
Reply
|
Rik
|
1/18/2008 4:18:19 PM
|
|
Thanks Luuk, it works!!
|
|
0
|
|
|
|
Reply
|
Plantky
|
1/18/2008 4:19:32 PM
|
|
|
4 Replies
262 Views
(page loaded in 0.052 seconds)
Similiar Articles: How to get latest date for each distinct entry? - comp.databases ...Hi, I have a table called "obs" with the following: observation INT AUTO_INCREMENT, morph VARCHAR, date DATE, plot VARCHAR, number INT, comment TEXT... How to count the number of unique entry of one field - comp ...How to get latest date for each distinct entry? - comp.databases ..... be done, but not if you want the field ... file - comp.soft-sys.matlab How to count number of ... retrieve most recent record for each user - comp.databases.mysql ...How to get latest date for each distinct entry? - comp.databases ... retrieve most recent record for each user - comp.databases.mysql ... How to get latest date for each ... get or query creation date of an record? - comp.databases ...How to get latest date for each distinct entry? - comp.databases ... get or query creation date of an record? - comp.databases ... How to get latest date for each distinct ... SQL0101N for a Select query - comp.databases.ibm-db2SQL0101N for a Select query - comp.databases.ibm-db2 How to get latest date for each distinct entry? - comp.databases ... SQL0101N for a Select query - comp.databases ... Multiple entries in patient record - comp.databases.filemaker ...How to get latest date for each distinct entry? - comp.databases ... retrieve most recent record for each user - comp.databases.mysql ... How to get ... How to count how many times ech row has been repeated? - comp.soft ...How to get latest date for each distinct entry? - comp.databases ... How to count how many times ech row has been repeated? - comp.soft ... How to get latest date for each ... howto: create a primary key on an existing table? - comp.databases ...How to get latest date for each distinct entry? - comp.databases ... Primary Key - comp.databases.filemaker How to get latest date for each distinct entry? - comp ... How to generate discrete combinations with fixed sum? - comp.soft ...... go to the help menu many times!! but how could I make ... 4 3 16 only but noth both) where the 16 is the sum of ... How to get latest date for each distinct entry? - comp ... still not able to get NTP to sync on windows 7 even w/ more ...What do the NTP entries in the event viewer say? ... more typical user experience I will just run the latest ... Clearly we will need a way for each time it is rebuild ... How to get latest date for each distinct entry? - comp.databases ...Hi, I have a table called "obs" with the following: observation INT AUTO_INCREMENT, morph VARCHAR, date DATE, plot VARCHAR, number INT, comment TEXT... How to get latest date for each distinct entry? - comp.databases ...Hi, I have a table called "obs" with the following: observation INT AUTO_INCREMENT, morph VARCHAR, date DATE, plot VARCHAR, number INT, comment TEXT, 7/24/2012 10:49:44 AM
|