1-- With JOIN
2-- No row if id does not exist in t2
3SELECT t1.name, t2.salary FROM t1 JOIN t2 on t1.id = t2.id;
4-- A row with a NULL salary is returned if id does not exist in t2
5SELECT t1.name, t2.salary FROM t1 LEFT OUTER JOIN t2 on t1.id = t2.id;
6
7-- With UNION: distinct values
8SELECT emp_name AS name from employees
9UNION
10SELECT cust_name AS name from customers;
11
12-- With UNION ALL: keeps duplicates (faster)
13SELECT emp_name AS name from employees
14UNION ALL
15SELECT cust_name AS name from customers;