Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete duplicate rows

Status
Not open for further replies.

tlaksh

Programmer
Feb 25, 2001
98
US
how can I delete duplicate rows from the table keeping only one row that has the max id. My table structure is like this

id Iscomputer ComputerName

The computername col has duplicate values. I need to keep only one row for each computername where iscomputer = 1. If the is computer value is 0 then I can have duplicate values. Also I want to keep the row that has the max id


Can anyone help me with this...thanks a ton.

vidya

 
try something like:
delete from yourtable where
id in
(
select id from
(
select id, computername,
(
select count (computername) x
from yourtable t
where t.id < yourtable.id
and t.computername < yourtable.computername
) x
from yourtable
) t where t.x > 1
) Ion Filipski
1c.bmp


filipski@excite.com
 
short change
where t.id < yourtable.id
should be
where t.id >= yourtable.id Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top