select max(id),userid from table group by userid

解决方案 »

  1.   

    忘记说明了,上面的表要和另外一个表关联,用userID,另外的这个表的userID是唯一的,我现在想取得关联后本表ID最大的一条记录,谢谢!@
      

  2.   

    select max(a.id),a.userid from a,b where a.userid = b.userid;
      

  3.   

    select max(table1.id),table1.userID from table1 left join table2 on table1.userID = table2.userID where ... group by table1.userID
      

  4.   

    select max(table1.id),table1.userID from table1 left join table2 on table1.userID = table2.userID where ... group by table1.userID
    好像用这条SQL语句查出来的只是主表和子表的其中一条ID最小的记录,而我要的是子表中ID最大的记录!