mysql數據庫DML操做說明

--語法參考:https://dev.mysql.com/doc/   (當前用的是5.6)html

https://dev.mysql.com/doc/refman/5.6/en/sql-syntax-data-manipulation.htmlmysql

--select 查詢sql

SELECT
column_1, column_2, ...FROM
table_1
[INNER | LEFT |RIGHT] JOIN table_2 ON conditions
WHERE
conditions
GROUP BY column_1
HAVING group_conditions
ORDER BY column_1
LIMIT offset, length;spa

--DISTINCT語句
做用:刪除select結果重複行.net

DISTINCT與GROUP BY區別:
DISTINCT子句是GROUP BY子句的特殊狀況。DISTINCT子句和GROUP BY子句之間的區別是GROUP BY子句可對結果集進行排序,而DISTINCT子句不進行排序。htm

--BETWEEN ... AND ...語句
至關於  >=min and <=max排序

--LIMIT offset, length解讀
offset:參數指定要返回的第一行的偏移量。第一行的偏移量爲0,而不是1。
length:指定要返回的最大行數。ip

--查詢時生成自增列實現get

SELECT
column_1, column_2, ... , (@n:=@n+1) as n FROM
table_1,(select @n:=0) as incrit

  --insert 插入

INSERT INTO tbl_name (col1,col2) VALUES(col2*2,15);

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

INSERT INTO tbl_name(a,b,c) select a,b,c from tbl_name2;

--update 修改

UPDATE t1 SET col1 = col1 + 1;

UPDATE t1 SET col1 = col1 + 1, col2 = col1;

UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;

UPDATE Table1 t1
join Table2 t2 on t1.ID=t2.t1ID
join Table3 t3 on t2.ID=t3.t2ID
set t1.Value=12345
where t3.ID=54321

--delete 刪除

DELETE FROM somelog WHERE user = 'jcole'

#只刪除b表
DELETE b FROM document_classification_copy a
INNER JOIN document_classification_copy b
on a.id = b.parent_id and a.parent_id=0

#a,b兩個表裏能關聯上的都刪除 DELETE a,b FROM document_classification_copy a INNER JOIN document_classification_copy b WHERE a.id=b.parent_id and a.parent_id=0;

相關文章
相關標籤/搜索