Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Query Help

$
0
0

Hi,

I'm writing a Coldfusion page to perform some DB cleanup. I'm needing some assistance with a query.   ID is the Primary key Int field with no duplicates. Updated is a bit field 1 or 0.  Vend_ID is a number. The rest are Varchar fields.

SELECT ID, Vend_ID, Comp, Zip_Code, Type, Work, Updated
FROM Vend_Comp
WHERE (Type = 'Poly') AND (Work = 'Second') AND (Zip_Code = 12345)
Now that park works fine. What I need is something to handle the returned records. I need to loop through results and select any with duplicate Vend_ID. Then delete the ones with the lower ID numbers.

Perhaps a sub query to pull out the one with duplicate Vend_ID... then a query to get Max(ID) and delete the ones <> to Max(ID)? Hmmmm...





Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>