0

I have a table1 with column 1 and 2

1        2
Banana   x
Apple    y
Orange   z

I want to call a SELECT on this table with an array as parameter: ['Banana', 'Apple']

I want to get the rows where column 1 contains Banana or Apple (elements of the array)

SELECT * FROM table1 WHERE column1 = 'Banana OR column1 = 'Apple'

But how is this working dynamically? Like where column1 = elemt in array....?

2 Answers 2

2

Use the ANY operator:

select *
from the_table
where the_column = any( array['Banana', 'Apple'] );
Sign up to request clarification or add additional context in comments.

Comments

1

Use the keyword IN:

SELECT * FROM table1 WHERE column1 IN ('Banana', 'Apple');

(reference doc.: https://www.postgresql.org/docs/current/functions-subquery.html#AEN16806)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.