Results 1 to 5 of 5

Thread: MySQL Query Question

  1. #1

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    Cool 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?

  2. #2
    scoutt
    Guest
    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>"

  3. #3

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    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.

  4. #4
    Hyperactive Member Pix's Avatar
    Join Date
    Feb 2001
    Location
    I'm not telling you (or them)
    Posts
    282
    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

  5. #5

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    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
  •  



Click Here to Expand Forum to Full Width