Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    54
    Thanks
    12
    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:

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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Code:
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • 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
    •