filter duplicates during join query

I'm looking for how to filter OUT duplicate values during a SQL query with joins.

e.g. in this example, I'd like to weed out any records that contain duplicate b.item_2 values when I run the query

SELECT a.item_1 , b.item_2 , c.item_3 
FROM table_A a
INNER JOIN table_B b
ON a.my_uid = b.my_uid
INNER JOIN table_C c ON b.myValue = c.myValue

Open in new window

Richard GouetteIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
I think you need to provide more information. For example, if your data came out like:

item_1   item_2   item_3 
A        B        A
A        B        B
A        B        C
C        B        A
C        B        B

Open in new window


Which results would you expect to be returned?
0
Richard GouetteIT ManagerAuthor Commented:
apologies..
If I had:
item_1   item_2   item_3 
A        B        A
A        B        B
A        B        C
C        B        A
C        B        B

Open in new window


And I wanted no dupes in column 3, I'd expect:

item_1   item_2   item_3 
A        B        C
C        B        A
C        B        B

Open in new window

0
Jan LouwerensSoftware EngineerCommented:
In your question, you say that you don't want duplicates in item_2. But in your comment, you say you don't want duplicates in item_3. Which is it?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ryan ChongCommented:
try

;with cte as (
 
SELECT a.item_1 , b.item_2 , c.item_3,
row_number() over (partition by a.item_1 , b.item_2 order by c.item_3 desc ) idx
 FROM table_A a INNER JOIN table_B b ON a.my_uid = b.my_uid INNER JOIN table_C c ON b.myValue = c.myValue

)
select item_1 , item_2 , item_3
from cte where idx = 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard GouetteIT ManagerAuthor Commented:
In your question, you say that you don't want duplicates in item_2. But in your comment, you say you don't want duplicates in item_3. Which is it?


either one..
0
Richard GouetteIT ManagerAuthor Commented:
deleted, because I realize that I'm not  providing enough info to make a logical query..

let me review this some more..
0
Richard GouetteIT ManagerAuthor Commented:
abandoned the effort, and went with a ..less civilised method
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.