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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate Records SQL 1

Status
Not open for further replies.

DVFS

Programmer
Sep 21, 2000
44
US
What is a quick SQL query to simply show me a list of duplicate records that exist in a database?
 
This would suggest that your tables do not have primary keys, or do you mean duplicate records when ignoring the primary key?
 
Duplicate records ignoring primary keys. Sorry.
 
This should work, I can't say how quick it will be without knowing how many records are in the table.
Code:
select * from tablename
where colname in(
	select colname from (
		select colname, cnt=count(*)
		from tablename
		group by colname) as subqry
	where cnt > 1)

 
select col1,col2,col2.... from table
groupby col1,col2,col3....
having count(*) > 1

Kishore MCDBA
 
Both samples worked great, I appreciate the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top