最簡單的select方式就是
SELECT *
FROM table
就是在對應的table內取得所有column,
以emp這個table為例
SELECT *
FROM emp
就可以取得emp內所有column的資料
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
---|---|---|---|---|---|---|---|
7839 | KING | PRESIDENT | - | 1981/11/17 | 5000 | - | 10 |
7698 | BLAKE | MANAGER | 7839 | 1981/05/01 | 2850 | - | 30 |
7782 | CLARK | MANAGER | 7839 | 1981/06/09 | 2450 | - | 10 |
7566 | JONES | MANAGER | 7839 | 1981/04/02 | 2975 | - | 20 |
7788 | SCOTT | ANALYST | 7566 | 1982/12/09 | 3000 | - | 20 |
7902 | FORD | ANALYST | 7566 | 1981/12/03 | 3000 | - | 20 |
7369 | SMITH | CLERK | 7902 | 1980/12/17 | 800 | - | 20 |
7499 | ALLEN | SALESMAN | 7698 | 1981/02/20 | 1600 | 300 | 30 |
7521 | WARD | SALESMAN | 7698 | 1981/02/22 | 1250 | 500 | 30 |
7654 | MARTIN | SALESMAN | 7698 | 1981/09/28 | 1250 | 1400 | 30 |
如果只想知道某些特定欄位的話,
需要將query修改一下
SELECT col1, col2, col3
FROM table
例如我只想知道 EMPNO, ENAME, JOB的話
就執行
SELECT empno,ename,job
FROM emp
EMPNO | ENAME | JOB |
---|---|---|
7839 | KING | PRESIDENT |
7698 | BLAKE | MANAGER |
7782 | CLARK | MANAGER |
7566 | JONES | MANAGER |
7788 | SCOTT | ANALYST |
7902 | FORD | ANALYST |
7369 | SMITH | CLERK |
7499 | ALLEN | SALESMAN |
7521 | WARD | SALESMAN |
7654 | MARTIN | SALESMAN |
同理,如果想得知所有job這個欄位的資料
就輸入
SELECT job
FROM emp
如下圖,其實有很多重複的資料
JOB |
---|
PRESIDENT |
MANAGER |
MANAGER |
MANAGER |
ANALYST |
ANALYST |
CLERK |
SALESMAN |
SALESMAN |
SALESMAN |
如果想要得到不重複的資料
可以加入DISTINCT
query如下:
SELECT
DISTINCT job
FROM emp
JOB |
---|
ANALYST |
CLERK |
SALESMAN |
MANAGER |
PRESIDENT |
這樣就可以得到不重複的資料了
0 Comments:
張貼留言