Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to perform WHERE in with multiple columns in postgres

I wants to do something like this,

SELECT * FROM product p
                    JOIN product_version pv ON p.id = pv.product_id
                    where (p.code, pv.product_version) in (("FF6",1), ("FF12", 1));

But this is giving error at in clause.
Can someone provide the correct syntax.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are not providing any information about the actual error neither about column types.

But, by the way, it really looks like that those double quotes are wrong because in Postgres strings are quoted using simple quotes ('), not double (").

Try:

SELECT *
FROM product p
JOIN product_version pv ON (p.id = pv.product_id)
where
    (p.code, pv.product_version) in (('FF6',1), ('FF12', 1))
;

Despite that, your query looks syntactically "correct" unless some kind of type mismatching we cannot foresee without more information.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading