一
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC]
[LIMIT {[offset
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE
[CHARACTER SET charset_name]
export_options
| INTO DUMPFILE
| INTO var_name [
[FOR UPDATE | LOCK IN SHARE MODE]]
簡化一下語法如下
select column
from table
[where condition]
[group by …]
[having …]
[order by …]
mysql> create table jokes(
mysql> insert into jokes values(
#計算列(select 用於檢索從一個或多個表中選取出的行
select
+
| total |
+
|
+
#從表Jokes中挑選所有的東西
select * from jokes;
+
| id | joketext | jokedate |
+
|
+
#選擇感興趣的列(投影)
select id
#我們是不是可以多少顯示一點笑話正文的內容呢?(預覽)
mysql> select id
+
| id | content | jokedate |
+
|
+
#統計表中記錄數
mysql> select count(*) as records from jokes;
+
| records |
+
|
+
#統計
select count(*) from jokes where jokedate >=
#笑話裡包含
mysql> select joketext as content from jokes where joketext like
+
| content |
+
| why not? |
+
#顯示
select joketext from where joketext like
員工表emp(empno
部門表dept(deptno
select deptno
select deptno
注意
select * from emp
where sal in ( select max(sal) from emp
group by deptno );(先按組排序
select * from emp order by sal desc;
limit子句可以被用於強制select語句返回指定的記錄數
(
select * from emp order by sal limit
óselect * from emp order by sal limit
(
select * from emp limit
From:http://tw.wingwit.com/Article/program/MySQL/201311/29479.html