I have Parent + Reference tables where
Reference table is as follows
Ref_ID PARENT_ID
-------------------
1 1
2 1
1 2
3 2
1 3
3 3
4 3
2 4
3 4
Trying to return all distinct parent rows WHERE ref_id in ( 2, 3 )
using a join instead of using a subquery
but duplicates are being returned for parent via join query
Any help is appreciated
FYI – there are 4-7 tables in the query ( depending on user selections )so performance is a huge factor
Ok,
First the code
The first query returns a distinct record of ParentID’s. It works fine because i haven’t requested for Ref_Id as well.
Just to explain you when you requesting for Ref_ID as well, the query tries to return a distinct ParentID’s. But look at your records you have two ParentID’s which equals to 4

But with Different Ref_ID so he returns them both. both of them matching the query rules