Re: [PHP-DB] Query select value on MAX Date

2006-02-25 Thread Neil Smith [MVP, Digital media]

At 08:47 25/02/2006, you wrote:

MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary=_=_NextPart_001_01C63997.1A6B1B7D
Date: Sat, 25 Feb 2006 08:07:36 +0900
Message-ID: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]
To: 'php-db@lists.php.net'
Subject: FW: [PHP-DB] Query select value on MAX Date

Dear All,

 Sorry, I wrote the wrong result.


You've posted 3x with different results so it's too confusing to work 
out what you *want* to get.


However I woudl write that query like so :

SELECT MAX(Date) as NewestDate, Value
FROM table
GROUP BY Category
HAVING Date=NewestDate

HTH
Cheers - Neil

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Query select value on MAX Date

2006-02-24 Thread Nur_Adman
Dear All,

 

I have table like this :

 

Id |   Category |   Date|
Value

1  |   A  | 2005-02-21   |
2000

2  |   A  | 2004-01-21   |
3000

3  |   B  | 2006-01-20   |
4000

4  |   B  | 2005-12-11   |
5000

 

I want to get the value for each Category where the date is MAX.

So I make the query like this :

 

SELECT MAX(Date), Value FROM table GROUP BY Category

 

But I get is :

 

Id |   Category |   Date|
Value

1  |   A  | 2005-02-21   |
2000

3  |   B  | 2006-01-20   |
4000

 

Could you help me please?

 

Thanks  Regards,

 

Anita