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 |
|
hendrasd
Starting Member
20 Posts |
Posted - 2003-08-13 : 00:31:04
|
| Hi guys,I have a table TTemporary with contents like this :Code ValueA1 3A2 4A3 5A2 5A3 3I want to delete rows on the table which has a value less than the maximum value for a certain Code. The result of the query would be like this :Code ValueA1 3A2 5A3 5I've thought a solution, but it is using Cursor method. Is there any way to do it without using Cursor ?Thanks in advance ...-- Never stop learning -- |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-08-13 : 00:44:15
|
| Delete all rows of a code that're less than the max value?Here's the rows of max valuesSELECT Code, MAX(Value) as MaxValue FROM TTemporary GROUP BY CodeHere's a Select that'll select all the other rowsSELECT *FROM TTemporary TINNER JOIN (SELECT Code, MAX(Value) as MaxValue FROM TTemporary GROUP BY Code) A ON A.Code = T.CodeWHERE A.MaxValue <> T.ValueNow to delete those rowsDELETE TFROM TTemporary TINNER JOIN (SELECT Code, MAX(Value) as MaxValue FROM TTemporary GROUP BY Code) A ON A.Code = T.CodeWHERE A.MaxValue <> T.ValueI haven't tried this. No warranty expressed or implied.Samps. pretty sure this doesn't work. It's an UPDATE syntax I used on the DELETE. |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2003-08-13 : 00:48:03
|
(Flailing sounds)Let's try this againDELETE FROM TTemporary TINNER JOIN (SELECT Code, MAX(Value) as MaxValue FROM TTemporary GROUP BY Code) A ON A.Code = T.CodeWHERE A.MaxValue <> T.Value |
 |
|
|
hendrasd
Starting Member
20 Posts |
Posted - 2003-08-13 : 00:57:12
|
| Yipiiiiii thanxxx ... >-(^_^)-<-- Never stop learning -- |
 |
|
|
|
|
|