Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2012
    Thanked 0 Times in 0 Posts

    Duplicate Records only where a specific condition exists

    I have a table containing Display Text, A Link Field, and a Category.
    I am trying to find duplicate links, BUT only if they have the same Category.

    Right now I am using a query that shows me all duplicates regardless of the category they are in. Can anyone help me figure out the missing piece for the same category part?

    Here is my query:

    SELECT *
    FROM patterns
    WHERE lnktxt
    IN (
    SELECT lnktxt
    FROM patterns
    GROUP BY lnktxt
    HAVING count( lnktxt ) >1
    ORDER BY lnktxt

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    SELECT P1.some, P1.fields
    FROM patterns AS P1, 
         ( SELECT lnktxt, category, COUNT(*) AS howmany
          FROM patterns 
          GROUP BY linktxt, category
          HAVING howmany > 1 ) AS P2
    WHERE P1.lnktxt = P2.lnktxt AND P1.category = P2.category

    If I understood what you were saying.
    Be yourself. No one else is as qualified.

  3. Users who have thanked Old Pedant for this post:

    mharrison (12-17-2012)


Posting Permissions

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