klind
klind

Reputation: 865

postgres sql select combination of two columns

A user can choose a list of option combinations and then search for them.

The sql could look like this.

select * from p where (option_type = 'X' and value = 'A') 
or (option_type = 'X' and value = 'B')
or (option_type = 'Y' and value = 'D')

But of course I do not want to have n number of or's

How would a good sql look like that performs ??? The user can choose many option combinations.

Thanks.

Upvotes: 4

Views: 4119

Answers (1)

user330315
user330315

Reputation:

No need for multiple ORs:

select * 
from p 
where (option_type, value) in ( ('X' ,'A'), ('X','B'), ('Y','D') ) 

Upvotes: 9

Related Questions