Naresh
Naresh

Reputation: 872

Can't able to retrieve the data using joins

I've two tables level & product, basically I need to find out level.id = 1, but I also need to know if it has product attached to this id in product table. There is a pdcatid in my product table. Now the query works only if this id also in product table, if product table doesn't have this id, it will fail and retrurn empty. How can I show both situations?

Here is my query I've tried

SELECT * 
FROM level 
RIGHT JOIN product on level.`id` = product.`pdcatid` 
WHERE level.`id` = 1

Thank You.

Upvotes: 0

Views: 30

Answers (2)

Ashish Bhavsar
Ashish Bhavsar

Reputation: 236

Try this:

SELECT * FROM level LEFT JOIN product on level.`id` = product.`pdcatid` WHERE level.`id` = 1

Upvotes: 1

Ravikiran kalal
Ravikiran kalal

Reputation: 1070

Use left join instead of right join.

Upvotes: 1

Related Questions