基礎(chǔ)
SELECT
[DISTINCT] column_name
[TOP number|percent column_name(s)]
[AS alias_name_for_column]
FROM table_name
[
WHERE column_name
[operator value]
[AND column_name operator value ] [OR column_name operator value ]
[LIKE pattern]
[IN (value1,value2,...)]
[BETWEEN value1 AND value2]
]
[AS alias_name_for_table]
[ORDER BY column_name ASC|DESC] ;DISTINCT: 不重復
TOP: 選擇少數(shù)記錄
INSERT INTO table_name [(column1,column2,column3,...)]
VALUES (value1,value2,value3,...) ;UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;DELETE FROM table_name
WHERE some_column=some_value;
pattern
- '%' 代表任意數(shù)量任意字符
- '-' 代表單個字符
- '[char]' 代表方括號內(nèi)任意字符
- '[!char]' or '[^char]' 代表不存在方括號內(nèi)任意字符
- eg.
SELECT * FROM Customers WHERE City LIKE '[a-c]%';
join
-
SELECT column_name(s)
FROM table1
INNER|LEFT|RIGHT|OUTER JOIN table2
ON table1.column_name=table2.column_name;
misc
- union 合并兩個select的結(jié)果唐断,不顯示duplicate的結(jié)果
- union all 合并兩個select的結(jié)果牡直,顯示duplicate的結(jié)果
- select into from 從現(xiàn)有表創(chuàng)建新表
- insert into select from 插入表