SELECT
SELECT field FROM table;
英文不會區分大小寫
SELECT
INSERT
UPDATE
DELETE
FROM
WHERE
ORDER BY … DESC
DESC
指定為降冪排列,沒有指定表示升冪排列。GROUP BY … HAVING
=
LIKE
<>
NOT LIKE
<
>
<=
>=
AND
OR
NOT
BETWEEN…AND…
IS NULL
NULL
為特殊資料型式,不適於使用 =
作比較。IS NOT NULL
NULL
為特殊資料型式,不適於使用 <>
作比較。*
%
_
SELECT field1,field2,field3 FROM table1;
SELECT * FROM table1;
SELECT field1,field2 FROM table1 WHERE field3>1000;
SELECT field1,field3 FROM table1 WHERE field5 LIKE 'A%';
SELECT field1,field2 FROM table1 WHERE field6 LIKE 'home' AND field7 LIKE 'city';
SELECT field1,field2 FROM table1 ORDER BY field3;
SELECT field1,field2 FROM table1 ORDER BY field3 DESC, field2;
SELECT field1,field2 FROM table1 GROUP BY field1 HAVING field3>100;
SELECT field1,field2 FROM table1,table2 WHERE table1.id=table2.id;
SELECT field1,field2 FROM table1 JOIN table2 ON table1.id=table2.id;
INSERT INTO table1 VALUES(value1,value2,value3,…);
INSERT INTO table1(field1,field2,field3,…) VALUES(value1,value2,value3,…);
UPDATE table1 SET field1=value1,field2=value2,… WHERE field3=value3;
DELETE FROM table1 WHERE field2=value2 AND field3=value3;
加入函數運算。
SELECT name, birth, CURDATE(), (YEAR(CURDATE())-YEAR(birth)) - (RIGHT(CURDATE(),5) < RIGHT(birth,5)) AS age FROM contactbook
SELECT name, birth FROM contactbook WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH))
SELECT name, birth FROM contactbook WHERE MONTH(birth) = MOD(MONTH(CURDATE()), 12) + 1
CURDATE() = CURRENT_DATE = CURRENT_DATE()
CURTIME() = CURRENT_TIME = CURRENT_TIME()
更新日期:
© 不惑仔 2011 起