Reputation: 10610
i want to select a single record using from two tables. But if you use SIMPLE JOIN
, it will only returns the value when the condition satisfies both the table and when we use LEFT
or RIGHT JOIN
also, it will return all the values from the LEFT
or RIGHT
table.
I'm using the following query,
SELECT *
FROM activity_feeds
LEFT OUTER JOIN activity_traders ON activity_feeds.feed_id = activity_traders.trdr_feed_id = '11'
I need to get the values from both tables only when activity_feeds.feed_id = activity_traders.trdr_feed_id = '11'
and when the value does not matches with the right table, it should return null for the columns in the right table. Please help!
Edit:Table structures added
Feeds
Traders
Upvotes: 0
Views: 95
Reputation: 263693
I assume that all the records are based from activity_feeds
whether or not the feed_id
exists on activity_traders
table as long as it will display all feed_id
that has a value of 11
. Try this one.
SELECT *
FROM activity_feeds a
LEFT OUTER JOIN activity_traders b
ON a.feed_id = b.trdr_feed_id
WHERE a.feed_id = '11'
Upvotes: 0
Reputation: 2041
SELECT * FROM activity_feeds LEFT OUTER JOIN activity_traders ON activity_feeds.feed_id =
activity_traders.trdr_feed_id where activity_traders.trdr_feed_id = '11'
Upvotes: 1
Reputation: 4957
ON activity_feeds.feed_id = activity_traders.trdr_feed_id
WHERE activity_traders.trdr_feed_id = '11'
Upvotes: 0