1

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.

1 Answer 1

1

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  
Sign up to request clarification or add additional context in comments.

1 Comment

very thanks , i do not know condition can be put in on

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.