select a.*,b.* from table1 a,table2 b
where not exits(select 1 from table where hideid=a.hideid and showid>a.showid) 
and a.fk=b.pk ;

解决方案 »

  1.   

    creat view as ( 上面的语句 ) ;
      

  2.   

    select 1 from table where hideid=a.hideid and showid>a.showid ? 看不懂。你是不是指select a.*,b.* from table1 a,table2 b
    where not exists(select * from table2 where hideid=a.hideid and showid>a.showid) 
    and a.fk=b.pk 
    这样也不行。
      

  3.   

    select a.*,b.* from table1 a,table2 b,
    (select hideid,max(showid) as maxshowid from table1 group by hideid) c
    where a.fk=b.pk and a.hideid = c.hideid and a.showid = c.maxshowid
    order by a.id
      

  4.   

    或者
    select a.*,b.* from table1 a,table2 b
    where not exists(select 1 from table1 where hideid= a.hideid and showid>a.showid) and a.fk=b.pk
      

  5.   

    行了,谢谢xzq111:)(前几天有点事,没上来,sorry)