lamiren
lamiren

Reputation: 65

SQL: Distinct record on certain condition

I'm using Redshift and I have table like this:

<Table A

enter image description here

I want query distinct record for Seq1& Seq2 which contain both 1111 and 2222 in ProductCode:

<Desired Result

enter image description here

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)

enter image description here

Any suggestion would be appreciated.

Upvotes: 1

Views: 65

Answers (1)

Fahmi
Fahmi

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

Related Questions