Left Join on mysql

SQL LEFT JOIN Syntax

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;

or:


SELECT column_name(s)
FROM table1
LEFT OUTER JOIN table2
ON table1.column_name=table2.column_name;

PS! In some databases LEFT JOIN is called LEFT OUTER JOIN.

Example: You have a surveys table and a services table and the id’s are both client_id


select surveys.date, surveys.client_id, surveys.score 
from surveys 
left join services on surveys.client_id=services.client_id 
where cpu like Xeon
group by surveys.client_id;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.