Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

mysql Full outer join two table

I have two tables socials , social_links
and I want all rows from frist 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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

frist 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

>Solution :

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  
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading