页:
[1]
|
mysql的select语句,重复语句中,只取一条,两个表关联时
select a.id b.id a.sort from sort a,class b
想取sort表中的sort字段的单一信息
谢谢了!! |
|
哎,没有人理我,经过我多天的研究,还是我自己来回答自己吧,呵呵
1 select id,distinct type from content
这个语句是错误的 因为distinct不可以用在第二个字段上
2 select distinct type,id from content
这个语句不报错,但distinct并没有起到作用
3 select id,group_concat(distinct type) from content group by type
group_concat是应用于mysql4.1版本中的
4 select id,count(distinct type) from content group by type
统计type字段
5 select distinct type,id from content group by type
这句是正确的
distinct在使用中,应注意以下几点:
1.distinct要在第一个字段上使用,不可以放在后面的字段上
2.需要去掉哪个重复的字段,就需要用group by把这个字段,分一下组
3.注意一下mysql的版本,这样一来,distinct就可以使用好了
呵呵
文章引用自:
[url]http://blog.sina.com.cn/ningning33[/url] |
| looking_for1 | 2007-11-12 05:01 AM |
|
| distinct后面还要用group by吗? |
|
厉害,帮你顶一下
------------------------------------------------------
[url]http://www.waibaoinfo.com[/url] 外包信息网 |
Powered by Discuz! Archiver 6.1.0
© 2001-2006 Comsenz Inc.
Processed in 0.00637 second(s), 2 queries | |
|
|