View Single Post
  #4 (permalink)  
Old 10-09-2006, 10:38 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 92
ben has disabled reputation
Default SQL 92 answer. Re: Selecting Duplicate Entries in a table?

Simon,

What about :

[sql]
SELECT torder_no,tpart_no, Qty FROM orders GROUP BY torder_no,tpart_no HAVING count(*)>1;
[/sql]

You could also try:

[sql]
SELECT t1.torder_no, t1.tpart_no, t1.Qty FROM orders as t1, orders as t2 WHERE t1.order_no = t2.order_no AND t1.id <> t2.id
[/sql]

I am assuming that you also have a primary key (id) in the orders table.

Once you delete all the duplicates you may want to put a unique constraint on the order_no column to avoid duplicates in future.
Reply With Quote