|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
the most recent address from each user by date
Alright here's a table I have:
Id Effective Addy 1 10/10/2003 123 Test Lane 1 12/10/2003 No Exist Court 1 1/5/2004 Here I am! 2 6/6/2003 Some place 3 12/25/2003 Old place 3 1/30/2004 Now Place I want to take the most recent address from each user by date- basically, I want this returned: Id Addy 1 Here I am! 2 Some place 3 Now Place. So I want each user's 'current' address. Is there a way in SQL to do this? EDIT: I kind of changed my question, I just want the Id and the current Addy. Can anyone give me a hand? Thanks a lot! |
|
#2
|
|||
|
|||
|
Okay- here's where I'm at:
SELECT test.Id, FIRST(test.Addy) AS CurrAddy FROM test GROUP BY test.Id, test.Effect ORDER BY test.Id,test.Effect DESC; That gives me: Id CurrAddy 1 Here I am! 1 No Exist Court 1 123 Test Lane 2 Some place 3 Now Place 3 Old place That's almost what I want, now I just need the top 1 of each Id number. Any suggestions? |
|
#3
|
|||
|
|||
|
Hi,
Following is the MS SQL Query. Change the table name and the column names accordingly Quote:
__________________
Regards, Brightlight
|
|
#4
|
|||
|
|||
|
This could also work...
Code:
select ID, Addy from Table 1 T1 join ( select ID, max(Effective) as maxEffective from Table1 T group by ID ) as A on T1.ID = A.ID and T1.Effective = A.maxEffective |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > the most recent address from each user by date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|