1/*Two tables: CUSTOMERS table and ORDERS table.
2ORDERS table contains STATUS attribute.*/
3SELECT
4 customers.customerNumber,
5 customerName,
6 orderNumber,
7 status
8FROM
9 customers
10LEFT JOIN orders ON
11 orders.customerNumber = customers.customerNumber;
1SELECT *
2FROM table_1
3RIGHT JOIN table_2
4ON table_1.common_field = table_2.common_field;
1SELECT table1.column1, table2.column2...
2FROM table1
3LEFT JOIN table2
4ON table1.common_field = table2.common_field;
5
1#The RIGHT JOIN keyword Return all rows from the right table (table_name2), even if there are no
2#matches in the left table (table_name1).
3syntax->SELECT column_name(s)
4FROM table_name1
5RIGHT JOIN table_name2
6ON table_name1.column_name=table_name2.column_name
7////example////
8SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
9FROM Persons
10RIGHT JOIN Orders
11ON Persons.P_Id=Orders.P_Id
12ORDER BY Persons.LastName
13
1-- LEFT OUTER JOIN is equivalent to LEFT JOIN
2-- b.VALUE1 is null when ID not in table2 (idem for c.VALUE1 in table3)
3SELECT a.ID, a.NAME, b.VALUE1, c.VALUE1 FROM table1 a
4 LEFT OUTER JOIN table2 b ON a.ID = b.ID
5 LEFT OUTER JOIN table3 c ON a.ID = c.ID
6WHERE a.ID >= 1000;
7
8-- ⇓ Test it ⇓ (Fiddle source link)
1#LEFT JOIN: Return all rows from the left table, even if there are no matches in the right
2#table
3syntax->SELECT column_name(s)
4FROM table_name1
5LEFT JOIN table_name2
6ON table_name1.column_name=table_name2.column_name
7////example/////
8SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
9FROM Persons
10LEFT JOIN Orders
11ON Persons.P_Id=Orders.P_Id
12ORDER BY Persons.LastName
13