Re: Selecting the latest entries

2003-12-27 Thread Roger Baklund
* Ville Mattila 
 I have a table containing weather reports of different types and cities. 
 The structure is following:
 - type
 - city
 - time
 - report
 
 Which kind of query should I use to select the latest reports of 
 specified cities. I mean, if I had three different types of reports for 
 Helsinki and Turku, how can I get them all in one query?

Use a sub-select if you can, or see the MAX-CONCAT trick:

URL: http://www.mysql.com/doc/en/example-Maximum-column-group-row.html 

-- 
Roger

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Selecting the latest entries

2003-12-25 Thread Ville Mattila
Hi there,

This subject might be discussed before, but I couldn't find any mail 
from the archives.

I have a table containing weather reports of different types and cities. 
The structure is following:
- type
- city
- time
- report

Which kind of query should I use to select the latest reports of 
specified cities. I mean, if I had three different types of reports for 
Helsinki and Turku, how can I get them all in one query?

One way is to make two queries: first to get the latest report time for 
each type/city...
SELECT MAX(time) FROM reports WHERE city IN ('Helsinki', 'Turku') AND 
type IN ('Observation', 'Forecast 1', 'Forecast 2') GROUP BY type, city;
... and then another query getting the report text for each time and 
city and type.

Anyway I find this not very good one and now wondering if there is any 
other way to make it in one query...

Thanks for any help. :)

Ville

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]