MySQL無重復查詢是MySQL中重要的一種查詢方式,下面就為您介紹MySQL無重復查詢的實現方法,希望對您能有所啟迪。
MySQL無重復查詢即獨有查詢,也就是查詢滿足條件的、但又互不相同的結果。首先讓我們看一個例子:
- select title from employee_data;
- +----------------------------+
- | title |
- +----------------------------+
- | CEO |
- | Senior Programmer |
- | Senior Programmer |
- | Web Designer |
- | Web Designer |
- | Programmer |
- | Programmer |
- | Programmer |
- | Programmer |
- | Multimedia Programmer |
- | Multimedia Programmer |
...
上述例子裡,我們在employee_data表裡查詢title(職務),注意到結果裡有許多是重復的。如果我們想得到沒有重復的結果,就可以用到mysql的關鍵字 - DISTINCT
- select DISTINCT title from employee_data;
- +----------------------------+
- | title |
- +----------------------------+
- | CEO |
- | Customer Service Manager |
- | Finance Manager |
- | Marketing Executive |
- | Multimedia Programmer |
- | Programmer |
- | Senior Marketing Executive |
- | Senior Programmer |
- | Senior Web Designer |
- | System Administrator |
- | Web Designer |
- +----------------------------+
- 11 rows in set (0.00 sec)
這樣就可以把公司的所有職務類別無重復地列出。另外,我們還可以同時使用DISTINCT和ORDBER BY把獨有的(無重復的)結果排序列出,例如:
- select DISTINCT age from employee_data
- ORDER BY age;
- +------+
- | age |
- +------+
- | 25 |
- | 26 |
- | 27 |
- | 28 |
- | 30 |
- | 31 |
- | 32 |
- | 33 |
- | 34 |
- | 35 |
- | 36 |
- | 43 |
- +------+
- 12 rows in set (0.00 sec)
mysql命令行cmd環境下轉編碼簡介
mysql命令行參數簡介
修復mysql表的兩種方法
php中數組插入mysql表的方法
MySQL表管理命令介紹