取出的结果应该是
      ID       NAME
      1         a
      2         b
这个SQL语句怎么写

解决方案 »

  1.   

    select a.* from a where id not in(select b.id from b)
    union all
    select a.* from a,b where a.id=b.id and b.endtime is null;
      

  2.   

    select * from a where (id not in (select id from b)) or (id in (select id from where endtime is null))
      

  3.   

    这样的SQL语句速度太慢了
    还有没有其他的方法?
      

  4.   

    select a.* from a,b where (a.id=b.id and b.endtime is null) or (a.id<>b.id)