Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-16-2012, 03:11 AM   PM User | #1
mharrison
New Coder

 
Join Date: Dec 2012
Posts: 52
Thanks: 12
Thanked 0 Times in 0 Posts
mharrison is an unknown quantity at this point
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
mharrison is offline   Reply With Quote
Old 12-17-2012, 01:05 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
mharrison (12-17-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:53 AM.


Advertisement
Log in to turn off these ads.