[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1940
  • Last Modified:

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?
0
olgavillamizar
Asked:
olgavillamizar
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Select id_plano, max(date), user from table where id = 'x' group by id_plano
0
 
incapitalCommented:
What result do you want to see? Do you want the max date for that user?
0
 
dstanley9Commented:
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



0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
olgavillamizarAuthor Commented:
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


0
 
dstanley9Commented:
Actually, pedro and pepe BOTH have the last date.  So which one wins?

Here's a start:

Select id, date, user from table where id = 'x' AND date =
( SELECT MAX(date) FROM table where id = 'x')

0
 
dstanley9Commented:
Sorry, I misread pepe's year.  But the scenatio still holds if you have two users with the highest date value for that ID.
0
 
olgavillamizarAuthor Commented:
Thank you
It works.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now