表结构
id  wllb wlmc  
1  01 试验1 
2  01 试验2
3  02 试验3
4  02 试验4
5  03 试验5
6  03 试验6
想要得到的结果是
id  wllb wlmc
2   01   试验2
4  02 试验4
6  03 试验6

解决方案 »

  1.   

    第一次
    $thissql="create temporary table tmp select max(id) as id from yxxl where sh='2' group by wllb  ";
    $query=mysql_query($thissql);
    底二次
    $thissql="select yxxl.* from yxxl,tmp where yxxl.id=tmp.id";
    $query=mysql_query($thissql);结果已得到
      

  2.   

    就一个联合查询就可以了:
    $sql="select a.* from yxx1 as a join (select max(id) as id from yxx1 where sh='2' group by wllb)as b on a.id=b.id";或者: $sql="select a.* from yxx1 id id(select max(id) as id from yxx1 where sh='2' group by wllb)
      

  3.   

    搞定了,谢谢大家!
    先合并,在拆解
    $thissql="SELECT  SUBSTRING_INDEX(Max(CONCAT_WS(',', id, wlmc) ), ',', 1)  as id, SUBSTRING_INDEX(max(CONCAT_WS(',', id, wlmc) ), ',', -1) as wlmc FROM yxxl where sh='2'  GROUP BY wllb";
      

  4.   

    多谢犬犬(心帆)翻译的MYSQL函数
    不敢独享,送给大家http://www.phpe.net/mysql_manual/06-3.html#IDX1187