USE SQLSERVER; SELECT * FROM EMP; SELECT DISTINCT MGR FROM EMP; SELECT DISTINCT DEPTNO FROM EMP; select distinct comm from emp; select distinct comm, deptno from emp; --查詢不重復的值 --distinct關鍵字 select * from emp; select distinct deptno from emp; select distinct deptno as "等級" from emp; select distinct sal from emp; select distinct job from emp; --NULL也是一個值,查詢唯一時也把NULL算入 select distinct comm from emp; select distinct deptno, comm from emp; select distinct comm, deptno from emp; select distinct job, ename from emp; --錯誤的寫法 select sal, distinct deptno from emp; --distinct使用來修飾select關鍵字的,不是用來修飾字段的 select distinct sal, distinct deptno from emp; --distinct使用來修飾select關鍵字的,不是用來修飾字段的 /* 注意: distinct 修飾的是 select 單個字段:select distinct 查詢為單個字段中不重復的 多個字段:select distinct F1, F2, F3... 查詢為字段組(所有字段)中不重復的 語法: select distinct F1, F2, F3... (單|多字段)from table; 例如: select distinct deptno, comm from emp 來自 tmp表 查詢 deptno, comm組合起來不包含重復數據 語意: 來自table中查詢的字段不包含重復數據(單|多字段)的組合 */