Home » SQL & PL/SQL » SQL & PL/SQL » duplicate name
duplicate name [message #480872] Thu, 28 October 2010 00:16 Go to next message
narang79
Messages: 135
Registered: June 2010
Senior Member

i have a employee table

i want to find out duplicate name from this table

so i write following query

select empname from employee
having count(empname) >1
group by empname

i find the result but problem is how i can find out the same name if it have any space like

ramkumar ram kumar both are same but above query did not
give this data

how i can solve it
Re: duplicate name [message #480874 is a reply to message #480872] Thu, 28 October 2010 00:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Hint use REPLACE to "remove" spaces in COUNT expression, use COUNT in its analytic form.

If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data.

Before, Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.

Regards
Michel
Re: duplicate name [message #480877 is a reply to message #480874] Thu, 28 October 2010 00:58 Go to previous messageGo to next message
narang79
Messages: 135
Registered: June 2010
Senior Member
sir please explain
Hint use REPLACE to "remove" spaces in COUNT expression, use COUNT in its analytic form.
Re: duplicate name [message #480879 is a reply to message #480877] Thu, 28 October 2010 01:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Sir please post a working test case.

Regards
Michel
Re: duplicate name [message #480880 is a reply to message #480872] Thu, 28 October 2010 01:02 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
SCOTT@dws>select * from t2;

COL1
--------------------
Ram Kumar
RamKumar
Rm Kumar
Ram
Ram Kumar

Elapsed: 00:00:00.67
SCOTT@dws>select replace(col1,' ') col1, count(replace(col1,' ')) cnt
  2  from t2
  3  group by replace(col1,' ');

COL1                        CNT
-------------------- ----------
RmKumar                       1
RamKumar                      3
Ram                           1


regards,
Delna
Re: duplicate name [message #480881 is a reply to message #480872] Thu, 28 October 2010 01:02 Go to previous messageGo to next message
ayush_anand
Messages: 417
Registered: November 2008
Senior Member
SQL> WITH datas AS
  2  (
  3  SELECT 'ramkumar' AS s1, 'ram kumar' AS s2 FROM dual union ALL
  4  SELECT 'Waldar'                    , 'Walder'                       FROM dual union ALL
  5  SELECT 'Perfect match'             , 'Perfect match'                FROM dual union ALL
  6  SELECT 'Awful match'               , 'Bad similitude'               FROM dual
  7  )
  8  SELECT s1, s2,utl_match.jaro_winkler(s1, s2)
  9    FROM datas
 10   WHERE  utl_match.jaro_winkler(s1, s2)> 0.96;

S1            S2             UTL_MATCH.JARO_WINKLER(S1,S2)
------------- -------------- -----------------------------
ramkumar      ram kumar                         9.741E-001
Perfect match Perfect match                       1.0E+000
Re: duplicate name [message #480885 is a reply to message #480880] Thu, 28 October 2010 01:18 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@delna,

You have no more the original name.

Regards
Michel
Re: duplicate name [message #480887 is a reply to message #480881] Thu, 28 October 2010 01:21 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
@ayush_anand

This is use a steamroller to squash a mosquito.

Regards
Michel
Re: duplicate name [message #480889 is a reply to message #480885] Thu, 28 October 2010 01:30 Go to previous messageGo to next message
vishalk
Messages: 33
Registered: October 2010
Member

Use REPLACE

Re: duplicate name [message #480890 is a reply to message #480885] Thu, 28 October 2010 01:31 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Michel Sir,
I didn't get this comment of yours.

regards,
Delna
Re: duplicate name [message #480893 is a reply to message #480890] Thu, 28 October 2010 01:39 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
When you group in this way you loose the orignal value: you have "RamKumar" and no more "Ram Kumar" or any of the similar values.

Regards
Michel
Re: duplicate name [message #480894 is a reply to message #480889] Thu, 28 October 2010 01:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
vishalk wrote on Thu, 28 October 2010 08:30
Use REPLACE

This is the same solution that delna.sexy and so the same drawbacks.

Note that some of us can't or don't want to download files.
So please post it online.
Before, Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.


Regards
Michel

Re: duplicate name [message #480895 is a reply to message #480893] Thu, 28 October 2010 01:42 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Good catch.

regards,
Delna
Re: duplicate name [message #480901 is a reply to message #480895] Thu, 28 October 2010 01:58 Go to previous messageGo to next message
vishalk
Messages: 33
Registered: October 2010
Member

Michel Sir

Sorry for uplode the file
But My Code
works...

Re: duplicate name [message #480909 is a reply to message #480901] Thu, 28 October 2010 02:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
No it does not, see my answers to delna.sexy.

Regards
Michel
Re: duplicate name [message #480957 is a reply to message #480909] Thu, 28 October 2010 10:37 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9094
Registered: November 2002
Location: California, USA
Senior Member
The following just demonstrates what Michel said.

SCOTT@orcl_11gR2> SELECT * FROM employee ORDER BY empname
  2  /

EMPNAME
---------------
kumar
ram
ram kumar
ramkumar
rm kumar

5 rows selected.

SCOTT@orcl_11gR2> SELECT empname duplicate_names
  2  FROM   (SELECT empname,
  3  		    COUNT (*) OVER (PARTITION BY REPLACE (empname, ' ', '')) cnt
  4  	     FROM   employee)
  5  WHERE  cnt > 1
  6  /

DUPLICATE_NAMES
---------------
ramkumar
ram kumar

2 rows selected.

SCOTT@orcl_11gR2>

Re: duplicate name [message #480958 is a reply to message #480957] Thu, 28 October 2010 10:46 Go to previous message
Michel Cadot
Messages: 68651
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Michel Cadot wrote on Thu, 28 October 2010 07:24
Hint use REPLACE to "remove" spaces in COUNT expression, use COUNT in its analytic form.

If you post a working Test case: create table and insert statements along with the result you want with these data then we will work with your table and data.

Before, Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.

Regards
Michel


Tell me and I'll forget; show me and I may remember; involve me and I'll understand



[Updated on: Thu, 28 October 2010 10:52]

Report message to a moderator

Previous Topic: exist
Next Topic: Adding conditions in CASE statement
Goto Forum:
  


Current Time: Fri May 17 00:07:33 CDT 2024