duplicate check by names [message #9600] |
Sun, 23 November 2003 00:06 |
kritika
Messages: 5 Registered: November 2003
|
Junior Member |
|
|
if we are tring to check duplicate names in a table can we write
slect a.lname
from name a, name b
where a.lname = a.lname ( OR SHOULD IT BE A 'LIKE' OPERATOR) where a.lname like b.lname ?
or does it not matter if we use any of '=' or 'like'
Cheers
Kritika
|
|
|
Re: duplicate check by names [message #9602 is a reply to message #9600] |
Sun, 23 November 2003 02:28 |
Adam
Messages: 15 Registered: October 2001
|
Junior Member |
|
|
As far as I know theres a big difference between = and like.
From what I gather, = means replace this value with this value. e.g. Name = Surname
What that is doing is replacing the Surname Value, with the Name value.
The like operator checks the reference of the information, e.g. is this information the same as this information....much like the .equals operator in Java.
I may be completly wrong and someone is proably gonna correct me. But if they don't...I can only assume mes is right...which will make a change
|
|
|
Re: duplicate check by names [message #9603 is a reply to message #9600] |
Sun, 23 November 2003 02:29 |
Adam
Messages: 15 Registered: October 2001
|
Junior Member |
|
|
As far as I know theres a big difference between = and like.
From what I gather, = means replace this value with this value. e.g. Name = Surname
What that is doing is replacing the Name Value, with the SurName value.
The like operator checks the reference of the information, e.g. is this information the same as this information....much like the .equals operator in Java.
I may be completly wrong and someone is proably gonna correct me. But if they don't...I can only assume mes is right...which will make a change
|
|
|
|
Re: duplicate check by names [message #9642 is a reply to message #9610] |
Tue, 25 November 2003 17:52 |
kritika
Messages: 5 Registered: November 2003
|
Junior Member |
|
|
Thanks for the above. But these duplicates actually have different recordIds but same record data. This is giving trouble in that I can't avoid duplicates being selected. I know that its possible to avoid them through PL/SQL scripts but I just like to know If its possible with SQL Scripts ?
Thanks
Kritika
|
|
|
|
Re: duplicate check by names [message #9655 is a reply to message #9647] |
Wed, 26 November 2003 20:36 |
kritika
Messages: 5 Registered: November 2003
|
Junior Member |
|
|
Sorry, about the confusion. I am trying to count and display duplicate records with a match based on person name. My SQL is
select distinct a.id, a.fname, a.lname
from name a, name b, duplicate
where a.lname = b.lname and
a.fname = b.fname and
a.id = duplicate.id
My table data looks something like this with 3 columns- Id, FirstName, LastName
And my current result looks like this
45 John Smith
89 George Harrop
65 John Smith
70 George Harrop
I would like a result like this below( without duplicates records being displayed and also so that I can count duplicates aswell) -
45 John Smith
89 George Harrop
And also this dupliacte condition is maintained in a table duplicate with these columns
id dup_id dup_flag
And table data looks like this
45 65 Y
Any ideas here ? Again I am looking only for SQL Script not PL/SQL
Thank You
Kritika
|
|
|
Re: duplicate check by names [message #9665 is a reply to message #9655] |
Thu, 27 November 2003 23:48 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
If I'm not mistaken, you can identify the original records by their id in the duplicate.id column. Than you could do sth like:SQL> Select * from t;
ID FNAME LNAME
---------- ------------------------- -------------------------
45 John Smith
89 George Harrop
65 John Smith
70 George Harrop
SQL> Select * From dups;
ID DUP_ID DUP_FLAG
---------- ---------- --------
89 70 Y
45 65 Y
SQL> Select t.id
2 , t.fname
3 , t.lname
4 From t
5 Where t.id In ( Select id
6 From dups
7 )
8 /
ID FNAME LNAME
---------- ------------------------- -------------------------
45 John Smith
89 George Harrop
SQL> MHE
|
|
|