【www.bbyears.com--mysql教程】
一、mysql去掉重复值的简单方法
例子:
table
id name
1 a
2 b
3 c
4 c
5 b
库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。
比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录。
代码如下 select distinct name from table得到的结果是:
name
a
b
c
二、取得表数据的组数
代码如下方法一、select count(distinct name) from table
方法二、SELECT count(1) as total FROM (select `a_id` from tablename group by `a_property`)
临时表名