SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying ALL Dupes.

    I am runing these queries in my phpmyadmin to find dupe subjects in a table:

    QUERY 1:

    SELECT SUBJECT, COUNT(SUBJECT) AS NumOccurrences
    FROM TABLE
    GROUP BY SUBJECT
    HAVING ( COUNT(SUBJECT) > 1 );


    QUERY 2:
    SELECT DISTINCT SUBJECT from TABLE
    group by SUBJECT HAVING count(SUBJECT) > 1;

    Both work perfectly fine for me, but the problem I am facing here is that it shows only the first record and not the other dupes with them.

    How Can I SELECT and Display all the dupes? Not only the first one.

    TIA.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    SELECT subject
         , other_columns
      FROM daTable
    INNER
      JOIN ( SELECT subject
               FROM daTable
             GROUP 
                 BY subject
             HAVING COUNT(*) > 1 ) AS d
        ON d.subject = daTable.subject
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •