1

I have this query:

select p1.cost as V1, p2.cost as V2 , p3.cost as V3 
from product p1, product p2, product p3 
where p1.id =1 and p2.id =2 and p3.id=3

In my product table I have just one row:

id   | name       | cost
1    | product1   | 20

As you can see here, I ll get empty result ! But how can I do to get:

V1   | V2  | V3
20   |     |

1 Answer 1

1

You could use left joins:

SELECT    p1.cost AS V1, p2.cost AS V2 , p3.cost AS V3 
FROM      product p1
LEFT JOIN product p2 on p2.id = 2
LEFT JOIN product p3 on p3.id = 3
WHERE     p1.id = 1
Sign up to request clarification or add additional context in comments.

1 Comment

and maybe WHERE p1.id = 1?

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.