List:General Discussion« Previous MessageNext Message »
From:Mauricio Pellegrini Date:April 12 2005 11:35pm
Subject:How to select the max value
View as plain text  
Hi,
I need to select the max value from a set of records but I also need the
primary key for that record.

The problem is that the record id may not be the same as the record max
value for the column as in the following example:

Table_x

Id	x_col	date_col
1	1	2005-04-11
2	1	2005-03-10
3	1	2005-04-12
4	1	2001-01-01

with 
	SELECT id, x_col, max(date_col) 
	 FROM table_x 
	 GROUP BY x_col

I would probably get the following result 

Id	x_col	date_col
4	1	2005-04-12

and what I would like to get is 

Id	x_col	date_col
3	1	2005-04-12

Is there a way to do that ?

Thanks in advance 
Mauricio



Thread
How to select the max valueMauricio Pellegrini13 Apr
  • Re: How to select the max valueDaniel Kasak13 Apr
    • Re: How to select the max valueDaniel Kasak13 Apr
  • Re: How to select the max valueRhino13 Apr
    • Re: How to select the max valueMauricio Pellegrini13 Apr