插入操作
INSERT [INTO] tbl_name [(col_name, ...)] {VALUES | VALUE} ({EXPR | DEFAULT}, ...), (...), ...; INSERT [INTO] tbl_name SET col_name={expr | DEFAULT}, ...; INSERT [INTO] tbl_name [(col_name, ...)] SELECT ...;
更新记录
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name={expr2|DEFAULT}] ... [WHERE where_condition]; UPDATE table_references SET col_name1={expr|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition]
删除记录
DELETE FROM tbl_name {WHERE where_condition};
查询记录
SELECT select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | position} [ASC|DESC], ...] [HAVING where_condition] [ORDER BY {col_name|expr|position} [ASC|DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}]]
引发子查询
- 比较运算符引发
- NOT IN 或 EXISTS引发
连接
table_reference {[INNER|CROSS] JOIN|{LEFT|RIGHT} [OUTER]JOIN} table_reference ON conditional_expr;
INNER JOIN、OUTER JOIN、JOIN等价,均为内连接,表示两表中符合条件的相交部分。
LEFT JOIN、RIGHT JOIN都是外链接, 分别表示左表的全部右表中符合条件的部分或右表全部左表符合部分。自身连接
一张表连接本身,适用于有parent_id的表。
多表删除
DELETE tbl_name[.*] [, tbl_name[.*]] ... FROM table_references [WHERE where_condition]