Shamseer PC
Shamseer PC

Reputation: 817

postgresql sub query has too many columns when checking against in condition

Here is my query:

SELECT * FROM table1
WHERE col1 IN (SELECT cola, colb, colc, cold FROM table2)

where all cols are of data type integer. When I execute this query I get "sub query has too many columns". What whould be the right way to do this?

Upvotes: 0

Views: 669

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 248175

SELECT * FROM table1
WHERE col1 = ANY (
                    (SELECT array_agg(ARRAY[cola, colb, colc, cold])
                        FROM a
                    )::integer[]
                 );

Upvotes: 1

Related Questions