我的字段是 id,proname,stime三个 你看看我的语句有什么问题? include("inc/conn.php"); $sql="select id,proname,stime from project where cateid='5' order by id desc limit 0,9 group by proname"; $result=mysql_query($sql); while($myrow=mysql_fetch_array($result))
问题出在是group by 和order by上面了,如何解决既按proname字段不重复查询,又按id顺序,还只查询9条纪录呢?sql语句如何写?
我把group语句提前就可以了,呵呵,谢谢楼上的老兄了!!!
SELECT DISTINCTSELECT DISTINCT id,proname,stime FROM project
楼主的SQL中可以将group by 放在前面: $sql="select id,proname,stime from project where cateid='5' group by proname order by id desc limit 0,9 "; 这个SQL在我的机器中运行没问题 另外group by proname 可以过滤proname重复字段,或者使用distinct关键字也可以
$sql="select distinct id,proname,stime from project where cateid='5' order by id desc limit 0,9 ";
id,proname,stime三个
你看看我的语句有什么问题?
include("inc/conn.php");
$sql="select id,proname,stime from project where cateid='5' order by id desc limit 0,9 group by proname";
$result=mysql_query($sql);
while($myrow=mysql_fetch_array($result))
$sql="select id,proname,stime from project where cateid='5' group by proname order by id desc limit 0,9 ";
这个SQL在我的机器中运行没问题
另外group by proname 可以过滤proname重复字段,或者使用distinct关键字也可以