kirk112 Posted November 2, 2006 Share Posted November 2, 2006 I am using the following query which highlights all duplicate email address[code]SELECT c.personal_email AS personal_email, COUNT( personal_email ) AS userCountFROM candidates AS cGROUP BY personal_emailHAVING userCount >1LIMIT 0 , 30[/code]The problem that I am having is that I want to be able to query for duplicate email address but be able to candidate_ref(primary key) for each of the records instead of the email address being grouped togetherThanks for you help! Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/ Share on other sites More sharing options...
kirk112 Posted November 3, 2006 Author Share Posted November 3, 2006 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-118995 Share on other sites More sharing options...
fenway Posted November 3, 2006 Share Posted November 3, 2006 I'm not sure I understand what you're trying to do... you want all of the matching candidate_ref UIDs for each e-mail address found? Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-119081 Share on other sites More sharing options...
kirk112 Posted November 3, 2006 Author Share Posted November 3, 2006 when I run the query it groups all the email address together,[code]personal_email userCount[email protected] 3[email protected] 2[email protected] 2[/code]but what I want to know is the candiadte_ref for each of the duplicated email address[code]candidate_ref personal_email 15 [email protected] 154 [email protected] 83 [email protected] 488 [email protected]44 [email protected]56 [email protected] 78 [email protected] [/code] Hope this makes senseRegardsShaun Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-119097 Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 You could always run a subquery (UNTESTED):[code]SELECT candidate_ref, personal_email FROM candidates WHERE personal_email IN ( SELECT c.personal_email AS personal_email, COUNT( personal_email ) AS userCountFROM candidates AS cGROUP BY personal_emailHAVING userCount >1LIMIT 0 , 30 )[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-119404 Share on other sites More sharing options...
kirk112 Posted November 7, 2006 Author Share Posted November 7, 2006 Hi FenwayThanks for your assistance, I have been playing around with the code you supplied and I keep getting #1241 - Operand should contain 1 column(s) I have tried every different way I can to solve this error without any success, Any ideas?I am using version 4.1.20 if that makes any difference? Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-120835 Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 Sorry, my bad... the inner query is returning two operands; try this one... I'm pretty sure you can use count() in the having clause, though it's not as pretty:[code]SELECT candidate_ref, personal_email FROM candidates WHERE personal_email IN ( SELECT c.personal_email AS personal_emailFROM candidates AS cGROUP BY personal_emailHAVING COUNT( personal_email ) >1LIMIT 0 , 30 )[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-120902 Share on other sites More sharing options...
kirk112 Posted November 7, 2006 Author Share Posted November 7, 2006 Thanks Fenway,Worked perfect!! Is there any reason that the query used so much resource and takes alot of time, it not a major issues just wondering if I could do anything to make it any quicker?(163 total, Query took 101.1717 sec)It is searching about 2000 recordsThanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-120976 Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 Do you have an index on personal_email? Post the EXPLAIN output -- it shouldn't take more than a fraction of a second. Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-121109 Share on other sites More sharing options...
kirk112 Posted November 8, 2006 Author Share Posted November 8, 2006 Thanks for your assistance, below is the result for explain output.[code]SQL querySQL query:EXPLAIN SELECT candidate_ref, personal_emailFROM candidatesWHERE personal_emailIN (SELECT c.personal_email AS personal_emailFROM candidates AS cGROUP BY personal_emailHAVING COUNT( personal_email ) >1) [ Edit ] [ Skip Explain SQL ] [ Create PHP Code ]id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY candidates ALL NULL NULL NULL NULL 1754 Using where 2 DEPENDENT SUBQUERY c ALL NULL NULL NULL NULL 1754 Using temporary; Using filesort [/code] Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-121507 Share on other sites More sharing options...
fenway Posted November 8, 2006 Share Posted November 8, 2006 You don't have any indexes? Quote Link to comment https://forums.phpfreaks.com/topic/25955-checking-for-duplicates-mysql/#findComment-121815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.