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 |
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-08-05 : 06:03:39
|
| If there are three columns Die_Sequence X Y1 2 52 2 53 2 54 2 65 2 76 2 87 2 8and I want get distinct rows on X and Y with largest Die_Sequence i.e., the resulting record set should beDie_Sequence X Y3 2 54 2 65 2 77 2 8what would be the query? |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-08-05 : 06:21:29
|
| Something like this should do it:SELECT MAX(t1.die_sequence), t1.x, t1.yFROM tablename t1JOIN( SELECT DISTINCT x, y FROM tablename) t2 ON t1.x = t2.x AND t1.y = t2.yGROUP BY t1.x, t1.yRaymond |
 |
|
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-08-05 : 06:57:20
|
| How can I delete the the other rows except the MAX Die_Sequence. I just want to delete the duplicate rows except the MAX Die_Sequence |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-08-05 : 07:05:46
|
| Delete the original table where the die_sequence is not in this result set.DELETE t3FROM tablename t3LEFT JOIN( SELECT die_sequence=MAX(t1.die_sequence), t1.x, t1.y FROM tablename t1 JOIN ( SELECT DISTINCT x, y FROM tablename ) t2 ON t1.x = t2.x AND t1.y = t2.y GROUP BY t1.x, t1.y) t4 ON t3.die_sequence = t4.die_sequenceWHERE t4.die_sequence IS NULLRaymond |
 |
|
|
real_pearl
Posting Yak Master
106 Posts |
Posted - 2004-08-05 : 07:39:19
|
| Thanks :), I did it this waydelete o from tblA owhere unit_number = 10 and die_sequence <> (select MAX(die_sequence)from tblA i where i.unit_number = o.unit_number and i.wafer_sequence = o.wafer_sequence and i.x = o.x and i.y = o.y) |
 |
|
|
|
|
|