Link to home
Start Free TrialLog in
Avatar of olgavillamizar
olgavillamizar

asked on

select last date from table

Hi!
I have a table with this fields:  id, date and user

I want to do something like that

Select id_plano, max(date), user from table where id = 'x'

but it doesnt work

Somebody could help me?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Select id_plano, max(date), user from table where id = 'x' group by id_plano
Avatar of incapital
incapital

What result do you want to see? Do you want the max date for that user?
id_plano is not in the list of columns you gave:

do you mean:

Select id AS id_plano, max(date), user from table where id = 'x' GROUP BY id, user



Avatar of olgavillamizar

ASKER

Sorry the correct select is:

Select id, max(date), user from table where id = 'x'

I try

Select id, max(date), user from table where id = 'x'
group by id, user

But it doesnt work because I obtanin this values

id         user       date
X         pepe      6/6/2005
X         ana        3/6/2006
X         pedro     6/6/2006

I want to obtain just

X   pedro    6/6/2006

because is the max date to this id


ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I misread pepe's year.  But the scenatio still holds if you have two users with the highest date value for that ID.
Thank you
It works.