khalid seleem
khalid seleem

Reputation: 117

mysql Full outer join two table

I have two tables:
socials and social_links

I want all rows from first table and related rows from second table.

My code:

SELECT socials.*, social_links.*
FROM socials
LEFT JOIN social_links ON socials.id=social_links.social_id  
WHERE social_links.site_id=1 

This code return 2 rows, but I want 4 rows where site_id=1.

First table socials:

id name
1 Facebook
2 Instagram
3 Linkedin
4 Messenger

Second table social_links:

id social_id site_id link
1 1 1 https://www.facebook.com/lolo
2 2 1 https://instagram.com/test
3 1 2 https://www.facebook.com/koko

I want all rows from socials join with social_links where site_id=1.

Upvotes: 1

Views: 61

Answers (1)

jitender
jitender

Reputation: 10429

instead of where add your condition in the join

SELECT socials.*,social_links.*
from socials     left join  social_links  on socials.id=social_links.social_id and social_links.site_id=1  

Upvotes: 1

Related Questions