表结构
id int
name varchar
actor varchar
content text
select distinct id,name,actor,content from temp
出错,因为distinct不可和text类型一起用;
其实我只需要distinct name就行了
用select distinct (name),id,actor,content from temp
仍不行。
各位有什么方法
------解决方案--------------------
---这里的保证id的值是唯一的
select name,id,actor,content
from temp t
where exists(select 1 from temp where t.name=name and t.id> id)
------解决方案--------------------
select name,id,actor,content
from temp a inner join (select min(id),name from temp group by name) b on a.id=b.id
------解决方案--------------------
select name,id,actor,content from table as T
where id =(select min(id) from table where name=T.name)
------解决方案--------------------
shuai45(付出总有回报,要做就做最好.)
--------------------------
你的写法有问题
select name,id,actor,content from table as T
where id in (select min(id) from table where name=T.name) ---这个地方要用in不是等号
------解决方案--------------------
name重复怎么取数,其它内容是按id大的还是小的,看来shuai45(付出总有回报,
的很好,要按大的改成max
------解决方案--------------------
用等号是对的呀
------解决方案--------------------
=号应该没问题 in也可以
------解决方案--------------------
你的sql 写的好乱~看看下面的能否执行
select a.program_id,a.name,a.director,a.playactor,a.content,d.count_total from vod_program a,vod_menu2program b,vod_program_menu c,vod_program_stat d where a.program_id=b.program_id and b.program_menu_id=c.program_menu_id and a.program_id=d.program_id and c.parent_id=239 and a.if_issue=1 and a.if_check=1 and
a.program_id in (select min(a.program_id) from vod_program where name=a.name)
------解决方案--------------------
大哥你提问的时候 能不能将长的sql写的结构化一些,让人有心情看
如:
select .........
from ........
inner join .........
inner join .........
where
...............
group by ...........