Microsoft
Software
Hardware
Network
Question : Need to turn a SQL select into a delete statement
I have the following SQL statement that I need to turn into a delete
SELECT update_id,DTTM_IMPORTED FROM PS_MAINTENANCE_LOG
GROUP BY update_id,DTTM_IMPORTED
HAVING Count(*) > 1
--- This was submitted but it did not leave one of the duplicate rows, it deleted all rows where the count(*) was greater than one.
delete from ps_maintenance_log
where (update_id,DTTM_IMPORTED) in
(
SELECT update_id,DTTM_IMPORTED FROM PS_MAINTENANCE_LOG
GROUP BY update_id,DTTM_IMPORTED
HAVING Count(*) > 1
)
Thanks in advance.
Answer : Need to turn a SQL select into a delete statement
can you try the below :
delete from ps_maintenance_log x
where exists ( select 1 from ps_maintenance_log y
where x.update_id = y.update_id
and x.DTTM_IMPORTED = y.DTTM_IMPORTED
and x.rowid < y.rowid );
Thanks
Random Solutions
Excel 2007 Can Not Display Images From Web
Increase Filesystem Size of RHEL 5
Retrieve a list of unique values from a list object
Roaming Profiles in Windows 7 Pro and SBS 2008
Latest Vsphere client
SQLCommandBuilder - GetUpdateCommand, GetInsertCommand and GetDeleteCommand Questions
IPv4 vs IPv6
Run the first php script in background - When done - run the next script ...
Give user rights to add computer to a domain
Proliant ML110 G4 Lost RAID and Randomly gives Error 0251