Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqlpal2009
Yak Posting Veteran
58 Posts |
Posted - 2009-04-07 : 14:11:57
|
| Hello All,I have to query all the rows for a detail table except the maximum line item number. Dump this select in another table and then delete all of these rows from the original table. Keep only one row having max line item number.Any idea on how to achieve this.Thanks in advace-S |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sqlpal2009
Yak Posting Veteran
58 Posts |
Posted - 2009-04-07 : 14:25:54
|
| Cleanup PPKManufactDetail table - RandID ManufactID LineItemID1 1 12 1 23 1 34 2 15 2 26 3 17 4 1And now I wanted to copy the only data where lineitemid is max for group by RandID and ManufactID to another table and then delete the same from this table.So this table would end up having these records.RandID ManufactID LineItemID3 1 35 2 26 3 17 4 1 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-07 : 15:08:11
|
SELECT RandID, ManufactID, LineItemIDFROM (SELECT RandID, ManufactID, LineItemID, ROW_NUMBER() OVER (PARTITION BY ManufactID ORDER BY LineItemID DESC) AS recIDFROM PPKManufactDetail) AS dWHERE recID = 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|