|
-
May 16th, 2002, 08:37 AM
#1
Thread Starter
Addicted Member
MySQL Query Question
I want to search one of my tables to find out how many duplicate email addresses I have. Now I know I could do this in a for loop but there's gotta be a way to use just one SQL statement to do that. Can this be done?
-
May 16th, 2002, 10:10 AM
#2
pretty easy.
PHP Code:
$sql = "select email from table where email = '[email protected]'";
$result = mysql_query ($sql);
if (!$result){ echo mysql_error();}
$num_check = mysql_num_rows($result);
echo"<br>found: $num_check<br>";
-
May 16th, 2002, 10:45 AM
#3
Thread Starter
Addicted Member
yeah that would work, here's the thing, I want to just find any matches without knowing the email address. So '[email protected]' needs to not be there.. unless I need to set the variable and run it through a loop. I thought there was a way to do it without a loop though. Like the IN statement, I never used it but I think its what I need.
-
May 16th, 2002, 11:04 AM
#4
Hyperactive Member
theoretically, you could do one query to get the number of records in total, then do another using the DISTINCT keyword in the SELECT clause to not include the duplicates
Then count the difference between the number of rows returned from both queries. That should give you the number of dupilcates
-
May 16th, 2002, 11:07 AM
#5
Thread Starter
Addicted Member
you know something, you're absolutely right... then I can just order by email address on select all records query and see which ones are right next to each other... thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|