0

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.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, the issue is because of the double quotes
0

You probably can't go with IN, depending on your goal you need to do something like:

where (p.code = "FF6" and pv.product_version = 1) or
(p.code = "FF12" and pv.product_version = 1)

or, if the logic above was not what you meant, maybe:


where p.code IN ("FF6", "FF12} AND pv.product_version IN (1) 

or


where p.code IN ("FF6", "FF12} OR pv.product_version IN (1) 

Comments

0

This code should work for you

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.