Im new to SQL - I've looked through the posts but couldn't quite work out the answer to my question sorry. I'm trying to do what I think should be a simple query, using a where/ or statement in my join clause.
The problem is I seem to be getting duplicates. Here is the code I'm using:
select A.[AuctionId], AA.attribute_id
from [auction] A
left join [auction_attribute] AA
on AA.auction_id = A.AuctionId
where AA.attribute_id = 127
or (AA.attribute_id = 132 and AA.text_data = 'USABLE')
I want to get all records where the attribute ID is 127 and ALSO the attribute 132 for the records needs to have the associated text_data 'USABLE', if that makes sense? A record can have multiple attribute IDs so I want to get all 127s where the text_data associated with their 132 is also 'USABLE'. I had done the query with a sub-query originally but I think this would be a more efficient way to do it, if only I could get it right!
The above is currently returning duplicate records and if I substitute 'or' with 'and' I get no records. Can anyone help please??