1SELECT tablenmae1.colunmname, tablename2.columnnmae
2FROM tablenmae1
3JOIN tablename2
4ON tablenmae1.colunmnam = tablename2.columnnmae
5ORDER BY columnname;
6
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;
4SELECT t1.*, t2.salary FROM t1 JOIN t2 on t1.id = t2.id;
5-- A row with a NULL salary is returned if id does not exist in t2
6SELECT t1.name, t2.salary FROM t1 LEFT OUTER JOIN t2 on t1.id = t2.id;
7
8-- With UNION: distinct values
9SELECT emp_name AS name from employees
10UNION
11SELECT cust_name AS name from customers;
12
13-- With UNION ALL: keeps duplicates (faster)
14SELECT emp_name AS name from employees
15UNION ALL
16SELECT cust_name AS name from customers;