|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I have following table
table NAME Id name group_id date_changed 1 candy 3 20/01/01 2 cake 3 20/02/01 3 dog 3 20/01/02 4 Cat 3 20/02/02 5 tree 3 20/01/03 6 Flower 3 20/03/03 I want to filter newest name for each group_id (by date_changed) like below 2 cake 3 20/02/01 4 Cat 3 20/02/02 6 Flower 3 20/03/03 If call query: Select * from NAME order by group_id, date_changed DESC, result will be all rows (is this case is 6 rows). using this result is very difficult please help me find appropriate query |
|
#2
|
|||
|
|||
|
you have to use a sub-quey to do what you need
but I think there is something wrong with your data...cuz I don't understand your end result...here's an exmaple with Pubs: select distinct au_id,(select Max(royaltyper) from titleauthor b where a.au_id=b.au_id ) as the MaxRoyaltyper from titleauthor a but here's what I think you query should look like: Select distinct goup_id,(select max(date_changed)from name B where a.group_id=b.group_id) as Last_date_changed from NAME A |
|
#3
|
|||
|
|||
|
Code:
Select * from NAME n where date_changed = (select max(date_changed) from name where group_id = n.group_id) |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Please help me grouping |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|