LEFT JOIN, RIGHT JOIN



LEFT JOIN 
SYNTAX
SELECT comma_separeted_column_names
FROM table1
LEFT JOIN table2 

ON table1.column_name = table2.column_name;



EXAMPLE
SELECT user.username, orders.order_id
FROM users
LEFT JOIN orders 
ON users.id = orders.order_id
ORDER BY users.username;

Note: Here this query will retrieve all the records from 
right table (users) and only matching record from orders table

RIGHT JOIN
SYNTAX
SELECT comma_separeted_column_names
FROM table1
RIGHT JOIN table2 

ON table1.column_name = table2.column_name;




EXAMPLE
SELECT users.username, orders.order_id
FROM orders
RIGHT JOIN users
ON users.id = orders.order_id
ORDER BY users.username;

Note: Here this query will retrieve all the records from 
right table (users) and only matching record from orders table