GROUP BY 語句可以實現某一列的去重查詢。
直接上語句: select io_dev_id from io_info where (TID=1 AND host_name='yang1') GROUP BY 1; 按照io_dev_id去重查詢。 p:順手加上與ORDER BY 和 distinct的區分使用 GROUP BY 是根據列撿選 ORDER BY 是根據列排序 distinct類似於 GROUP BY ,但是只能放在 select 後面,被篩選的字段前面。 如:select distinct a,b,c from tb1; 選出的是a、b、c三列值都相同的數據。 摘取的mysql 5.6 reference manual中的內容: In most cases, a DISTINCT clause can be considered as a special case of GROUP BY. For example, the following two queries are equivalent: SELECT DISTINCT c1, c2, c3 FROM t1 WHERE c1 > const; SELECT c1, c2, c3 FROM t1 WHERE c1 > const GROUP BY c1, c2, c3;