用分组: select comid,min(title) subdircode,min(ssubdircode),min(content) from softinfo where content like '%".$key."%' group by comid order by pub_date desc
同意~Select 在选择的时候不知道怎么选择!
要查询comid的唯一值,那么title subdircode,ssubdircode,content 这些字段不同的时候,你要决定怎么取舍,不能简单地这样列出来。你或者去最大或者取最小,否则肯定不行啊 select comid,min(title) min(subdircode),min(ssubdircode),min(content) from softinfo where content like '%".$key."%' group by comid order by pub_date desc
列名 'softinfo.pub_date' 在 ORDER BY 子句中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
在这一子查询或聚合表达式中,text、ntext 和 image 数据类型无效。
select comid,min(title) subdircode,min(ssubdircode),min(cast(content as varchar(8000))) from softinfo where content like '%".$key."%' group by comid order by pub_date desc
select comid,min(title) subdircode,min(ssubdircode),min(content)
from softinfo where content like '%".$key."%'
group by comid
order by pub_date desc
select comid,min(title) min(subdircode),min(ssubdircode),min(content)
from softinfo where content like '%".$key."%'
group by comid
order by pub_date desc
---------------------
这段看不懂 是不是括号打短了?
from softinfo where content like '%".$key."%'
group by comid
order by pub_date desc