Heisenberg
Heisenberg

Reputation: 5279

How to select multiple condition in Redshift

I have like following table

type value
A   true
A   false
B   true
B   false
C   true
C   true

and I would like to get following result first type A or B must be selected, then type B and value true must be dropped

type value
A    true
A    false
B    false

I tried like following query

select *
from table
where type in ('A','B')
and (type,value) not in ('B','true')

but it returned like following error arguments of row IN must all be row expressions;

What is the wrong point of this? Are there any way to achieve this?

If someone has opinion, please let me know Thanks

Upvotes: 0

Views: 1453

Answers (2)

Dpk
Dpk

Reputation: 1

Make this a tuple by adding double paranthesis on the right side on the equal to sign

PFB corrected query

select *
from table
where type in ('A','B')
and (type,value) not in (('B','true'))

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520888

I think you want:

SELECT *
FROM yourTable
WHERE type = 'A' OR type = 'B' AND value = false;

Here is a demo of the above query.

Upvotes: 1

Related Questions