Home » SQL & PL/SQL » SQL & PL/SQL » duplicate column
duplicate column [message #605003] Mon, 06 January 2014 18:27 Go to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
is there a way i can run a query that will show me in a table to find if in a specific collumn there is a duplicate?
i have this table
CREATE TABLE PREMIER.P_LEAD
(
  LEAD_ID                        NUMBER(12)     NOT NULL,
  SMR_GLOBAL_NAME                VARCHAR2(60 BYTE),
  SMR_TIME_STAMP                 DATE,
  LEAD_TYPE                      VARCHAR2(3 BYTE) DEFAULT 'RG' NOT NULL,
  RECEIVE_MAIL_IND               VARCHAR2(1 BYTE) DEFAULT 'Y' NOT NULL,
 
  USERNAME                       VARCHAR2(60 BYTE),
 
) 

which has more that 10 million records, i want to find two records that have the USERNAME the same/duplicate?
not a specific record just want to find one that is the same
is this possible?


[EDITED by LF: fixed topic title typo; was "collumn". Applied [code] tags]

[Updated on: Tue, 07 January 2014 09:17] by Moderator

Report message to a moderator

Re: duplicate collumn [message #605004 is a reply to message #605003] Mon, 06 January 2014 18:32 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT USERNAME, COUNT(*) FROM P_LEAD GROUP BY USERNAME WHERE COUNT(*) > 1;
Re: duplicate collumn [message #605005 is a reply to message #605004] Mon, 06 January 2014 18:37 Go to previous messageGo to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
is it missing something,i get command not properly ended
Re: duplicate collumn [message #605006 is a reply to message #605005] Mon, 06 January 2014 18:40 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
SELECT USERNAME, COUNT(*) FROM P_LEAD WHERE COUNT(*) > 1 GROUP BY USERNAME;
Re: duplicate collumn [message #605007 is a reply to message #605006] Mon, 06 January 2014 18:42 Go to previous messageGo to next message
nataliafoster26
Messages: 64
Registered: October 2013
Member
aww man,
"ORA-00934: group function is not allowed here"
is what i get
Re: duplicate collumn [message #605008 is a reply to message #605007] Mon, 06 January 2014 18:47 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member

1* SELECT JOB, COUNT(*) FROM EMP HAVING COUNT(*) > 1 GROUP BY JOB
SQL> /

JOB COUNT(*)
--------- ----------
CLERK 4
SALESMAN 4
MANAGER 3
ANALYST 2
Re: duplicate collumn [message #605009 is a reply to message #605007] Mon, 06 January 2014 18:49 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
BS has got has where and having clauses confused, should be:
SELECT USERNAME, COUNT(*) FROM P_LEAD GROUP BY USERNAME HAVING COUNT(*) > 1;
Re: duplicate collumn [message #605093 is a reply to message #605009] Tue, 07 January 2014 05:37 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
This must have been a tough day for BlackSwan.
Re: duplicate collumn [message #605094 is a reply to message #605093] Tue, 07 January 2014 05:41 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
Littlefoot wrote on Tue, 07 January 2014 11:37
This must have been a tough day for BlackSwan.

Either that or someone has hacked BS's account Smile
Re: duplicate collumn [message #605106 is a reply to message #605093] Tue, 07 January 2014 07:12 Go to previous message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Should have COPIED and PASTED the WHOLE SQL*PLUS SESSION Cool
Previous Topic: DML written on a script autocommits after a DDL in the same script without any commit statements?
Next Topic: can a string be used with IN within a query?
Goto Forum:
  


Current Time: Thu Apr 25 04:06:39 CDT 2024