SQL 笔记
Self Join
查找所有比Allen 工资高的员工
table: employee
SELECT a.* ---select all columns in table a
FROM employee AS a, employee AS b ----self join
WHERE a.salary >b.salary
AND b.name ='ALLEN';
也可用子查询subquery`
SELECT *
>FROM employee
>WHERE salary> (SELECT salary
> FROM employee
> WHERE name ='ALLEN');
SQL执行顺序
8)SELECT (9)DISTINCT
(1)FROM [left_table]
(3)<join_type> JOIN <right_table>
(2)ON <join_condition>
(4)WHERE <where_condition>
(5)GROUP BY <group_by_list>
(6)WITH <CUBE | RollUP>
(7)HAVING <having_condition>
(10)ORDER BY <order_by_list>
(1