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 |
|
johnsql
Posting Yak Master
161 Posts |
Posted - 2006-12-05 : 16:33:01
|
| Hi, I have a following table, and rows with the same SectionID, RoomID, TimeID, DayID, PeriodID, and ScheduleTyID are delicately inserted. Column “SessionID” is a primary key of the table. So, on viewing the table, you see sectionID= 9634, 9636 have duplicate row insertions:SectionID SessionID RoomID TimeID DayID PeriodID ScheduleTyID ----------| ----------| ----------| ----------| ----------| ----------| -----------| 9634 23444 21 135 6 30 29634 24312 21 135 6 30 29636 23401 9 71 8 15 39636 24269 9 71 8 15 39638 23180 9 108 13 29 4 I would like to remove row with sessionIDs of 23444 (bigger sessionIDs), 23401 of sectionIDs of 9634 and 9636. What is the best way (quick and less scripts) way to remove such duplicates? Any help/hint is greatly appreciated.JohnSql |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-05 : 16:43:36
|
| 23444 is bigger than 24312?delete afrom yourtablenamehere ainner join (select sectionid, min(sessionid) mid from yourtablenamehere group by sectionid) don d.sectionid = a.sectionid and d.mid <> a.sessionidIf you want to keep the biggest sessionid, just replace MIN with MAX.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|