45,000 Jobs - Get an Interview Call,  Post Your Resume Here
SURESHKUMAR.NET FORUMS
Registered Member Login:
Not a member? Register today!



Welcome to the SURESHKUMAR.NET FORUMS.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.




Need SQL to find duplicate records?

        

Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-06, 04:50 AM   #1 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Posts: 2,379
Blog Entries: 4
Thanks: 118
Thanked 319 Times in 238 Posts
Rep Power: 60 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Hi All,

I have a table "MyTable" with a primary column called "SNO". Let the other columns called A,B,C and D. There is some data in the table.

I want to know if there are any duplicate records. But, as SNO field is generated & inserted by a trigger, there is no chance that it will have a duplicate value. So, we have to compare other columns to get the duplicate records.

I want to know the query which I can use to know the records those were duplicates of others.

Thanks,
Krishna

sk_kireeti is offline Offline   Reply With Quote
Old 08-04-06, 05:53 AM   #2 (permalink)
Senior Member
 
Join Date: Apr 2006
Location:
Posts: 151
Thanks: 0
Thanked 8 Times in 5 Posts
Rep Power: 5 jsangeetha has disabled reputation


Hi Krishna


SELECT A,B,C,D, count(*)
FROM MyTable
GROUP BY A,B,C,D
HAVING count(*) > 1


This query should help you identify the duplicate rows. This would group all the records with the values of columns A,B,C and D and then count the no. of rows in that group. If the Count is more than1 then its a duplicate.


Hope this helps.


Sangeetha



Edited by: jsangeetha
jsangeetha is offline Offline   Reply With Quote
Old 08-04-06, 06:28 AM   #3 (permalink)
Super Moderator
 
sk_kireeti's Avatar
 
Join Date: Feb 2006
Posts: 2,379
Blog Entries: 4
Thanks: 118
Thanked 319 Times in 238 Posts
Rep Power: 60 sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute sk_kireeti has a reputation beyond repute
Hi Sangeetha,

Thanks for the reply!!!

Going forward, I have copied the same table onto another DB. But, it is on different character set. So, some characters were interpreted as special characters while copying data. Now I want to know which are the rows those have the changed charaters. I mean the rows that don't match with the old one.

query used to copy table onto new DB is
create table mytable as (select * from mytable@old_db);

NOTE: "old_db" is the DB connection I have in new DB to connect to my old DB.

Thanks,
Krishna

sk_kireeti is offline Offline   Reply With Quote
Reply

Tags
duplicate , records , sql


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +6.5. The time now is 10:31 AM.

More Interview Questions Here...

Content Relevant URLs by vBSEO 3.3.0