Home  |  Forums  |  914 Info  |  Blogs
 
914World.com - The fastest growing online 914 community!
 
Porsche, and the Porsche crest are registered trademarks of Dr. Ing. h.c. F. Porsche AG. This site is not affiliated with Porsche in any way.
Its only purpose is to provide an online forum for car enthusiasts. All other trademarks are property of their respective owners.
 

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> OT: SQL Question ..., what's the easiest way to ...
SirAndy
post Mar 17 2005, 07:11 PM
Post #1


Resident German
*************************

Group: Admin
Posts: 41,644
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



SQL Question:

what's the easiest way to find duplicates in a table?

let's say i have a table (tbl_Users) with 20000 rows and the table has a column for the users email addy (sEmail) and i want to list all the accounts that have duplicate email addys.

i could run a script that takes each row and runs a count(*) on that addy, but that'll take forever.
anything simpler than that ???

(IMG:http://www.914world.com/bbs2/html/emoticons/idea.gif) Andy
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Sparky
post Mar 17 2005, 07:15 PM
Post #2


Mahna Mahna!
***

Group: Members
Posts: 1,134
Joined: 21-June 03
From: Spencer, MA
Member No.: 847



SELECT

FROM
tablename
GROUP BY

HAVING
count(*) > 1


But then again my sql is a bit rusty...

My best,
Mike D.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Part Pricer
post Mar 17 2005, 07:17 PM
Post #3


Believe everything I post
***

Group: Benefactors
Posts: 1,825
Joined: 28-December 02
From: Danbury, CT
Member No.: 35



I've done this with MySQL tables. I've just exported the table and imported it into Excel. Then sort by the column you want. Then, add a column that contains a formula that is true if a value is the same as the value in the row above it.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
john rogers
post Mar 17 2005, 07:20 PM
Post #4


Senior Member
***

Group: Members
Posts: 1,525
Joined: 4-March 03
From: Chula Vista CA
Member No.: 391



Do it like this:

sqlplus> delete from userID.my_email_data a where rowid <
(select max(rowid)
from userID.my_email_data b
where b.address = a.address
and b.username = a.username);


Notes: userID is the schema owner, my_email_data is the name of the table and address, username are the fields to check for dupes to. You can not use any functions such as substr(....) or you'll get inconsistant results. Additionally, the email field entries have to be exacly alike, even to case or it will fail cause then they aren't really duplicates!
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Mar 17 2005, 07:34 PM
Post #5


Resident German
*************************

Group: Admin
Posts: 41,644
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (Paul Heery @ Mar 17 2005, 05:17 PM)
Then sort by the column you want.

ok, how the heck do i sort a column in excel by name ????

(IMG:http://www.914world.com/bbs2/html/emoticons/confused24.gif) Andy
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Mar 17 2005, 07:37 PM
Post #6


Resident German
*************************

Group: Admin
Posts: 41,644
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (SirAndy @ Mar 17 2005, 05:34 PM)
ok, how the heck do i sort a column in excel by name ????

ok, got it ...

that worked!
(IMG:http://www.914world.com/bbs2/html/emoticons/beerchug.gif) Andy
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Part Pricer
post Mar 17 2005, 07:37 PM
Post #7


Believe everything I post
***

Group: Benefactors
Posts: 1,825
Joined: 28-December 02
From: Danbury, CT
Member No.: 35



Select the entire worksheet. Then go to Data then Sort. Choose the column you want to sort by.

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
JB 914
post Mar 17 2005, 07:38 PM
Post #8


Daddy! Finish my car NOW!!!
***

Group: Members
Posts: 1,593
Joined: 26-September 04
From: Garden Grove, CA
Member No.: 2,831



QUOTE (SirAndy @ Mar 17 2005, 05:34 PM)
QUOTE (Paul Heery @ Mar 17 2005, 05:17 PM)
Then sort by the column you want.

ok, how the heck do i sort a column in excel by name ????

(IMG:http://www.914world.com/bbs2/html/emoticons/confused24.gif) Andy

highlight the rows ( without the column header row at the top) then use data\filter\advanced filter to sort the data. they have a check box for unique records.

hope this helps
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Part Pricer
post Mar 17 2005, 07:41 PM
Post #9


Believe everything I post
***

Group: Benefactors
Posts: 1,825
Joined: 28-December 02
From: Danbury, CT
Member No.: 35



QUOTE (joe buckle @ Mar 17 2005, 08:38 PM)
highlight the rows ( without the column header row at the top) then use data\filter\advanced filter to sort the data. they have a check box for unique records.


Choosing Unique Records will hide the dupes.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
JB 914
post Mar 17 2005, 07:49 PM
Post #10


Daddy! Finish my car NOW!!!
***

Group: Members
Posts: 1,593
Joined: 26-September 04
From: Garden Grove, CA
Member No.: 2,831



QUOTE (Paul Heery @ Mar 17 2005, 05:41 PM)
QUOTE (joe buckle @ Mar 17 2005, 08:38 PM)
highlight the rows ( without the column header row at the top) then use data\filter\advanced filter to sort the data. they have a check box for unique records.


Choosing Unique Records will hide the dupes.

then you can import the now "good" records table back to SQL
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Part Pricer
post Mar 17 2005, 07:51 PM
Post #11


Believe everything I post
***

Group: Benefactors
Posts: 1,825
Joined: 28-December 02
From: Danbury, CT
Member No.: 35



I think Andy just wants to identify the dupes. I think he would cause some problems if he abitrarily deleted the record that appeared second for duplicate email addresses. What if he was deleting the wrong account?

User is offlineProfile CardPM
Go to the top of the page
+Quote Post
JB 914
post Mar 17 2005, 08:06 PM
Post #12


Daddy! Finish my car NOW!!!
***

Group: Members
Posts: 1,593
Joined: 26-September 04
From: Garden Grove, CA
Member No.: 2,831



this might help

http://office.microsoft.com/en-us/assistan...1366161033.aspx

(IMG:http://www.914world.com/bbs2/html/emoticons/biggrin.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
SirAndy
post Mar 17 2005, 08:21 PM
Post #13


Resident German
*************************

Group: Admin
Posts: 41,644
Joined: 21-January 03
From: Oakland, Kalifornia
Member No.: 179
Region Association: Northern California



QUOTE (Paul Heery @ Mar 17 2005, 05:51 PM)
What if he was deleting the wrong account?

yeah, i have to go through them by hand and figure out which ones are used and which ones are the ghosts ...

i found 531 duplicate accounts ...
(IMG:http://www.914world.com/bbs2/html/emoticons/wacko.gif) Andy

PS: i changed the code so now it catches duplicate email addys upon registration. should have done that in the first place. oh well ... (IMG:http://www.914world.com/bbs2/html/emoticons/headbang.gif)
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th May 2024 - 01:46 AM