|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with SELECT syntax
I have a table that has unit id, date, time, etc. I would like to select each unit id with the last date it has in the table. The original table is in chronological order. The result should have each unit listed once with the latest date in the table.
For Example: unit id Date Time 00100 01/12/2007 8:00 00100 01/12/2007 8:45 00200 01/12/2007 8:50 00100 01/13/2007 13:30 00300 01/13/2007 13:45 00100 01/14/2007 11:00 00200 01/14/2007 11:30 the result should be: 00100 01/14/2007 11:00 00200 01/14/2007 11:30 00300 01/13/2007 13:45 |
|
#2
|
||||
|
||||
|
Off the top of my head, try:
SELECT unit_id, max(date_field) FROM table GROUP BY unit_id
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter! DevArticles Forum Moderator "The net is a waste of time, and that's exactly what's right about it." -- William Gibson |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > Help with SELECT syntax |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|