I need a SQL query which will fetch me the list of products which has different values for a same id and product is of table A and Id and values are of table B and both the tables can be joined by column name prod_id
Output I want:
- List item
product |
---|
abc |
So in output I want only the product abc because it has different values for their respective id and I don’t need xyz because it has same values for their respective id
I tried but I’m not getting what I want as mentioned above
CodePudding user response:
select distinct product
from your_table
group by product, id
having count(distinct values) > 1
CodePudding user response:
this query seems to do the trick
SELECT distinct product from mytemp group by product, id, `values` having count(1) = 1