Reputation: 65
I'm using Redshift and I have table like this:
<Table A
I want query distinct record for Seq1& Seq2 which contain both 1111 and 2222 in ProductCode:
<Desired Result
I have tried the following query but of course not worked as I needed
SELECT DISTINCT Seq1, Seq2
FROM A
WHERE ProductCode IN (1111,2222)
<Result(NG)
Any suggestion would be appreciated.
Upvotes: 1
Views: 65
Reputation: 37473
You can try the below -
SELECT Seq1, Seq2
FROM A
WHERE ProductCode IN (1111,2222)
group by Seq1, Seq2
having count(distinct productcode)=2
Upvotes: 1