怎么把下面两条sql写条一条sql
1.
select * from Table_Teacher as c where c.state between 2 and 4 and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ') 
and c.ets like '%et1%' order by c.state asc, c.addtime desc
结果显示3条2.
select * from Table_Teacher as c where c.state in(1,2,10) and c.addby='chris' and c.location in
('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ') 
and (c.ets is null or c.ets not like '%es1%') order by c.state asc, c.addtime desc
结果显示124条3.我要怎么把这两个sql合并,写成一条sql语句

解决方案 »

  1.   

    (select * from Table_Teacher as c where c.state between 2 and 4 and c.addby='chris' and c.location in
    ('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')  
    and c.ets like '%et1%' order by c.state asc, c.addtime desc)
    union all
    (select * from Table_Teacher as c where c.state in(1,2,10) and c.addby='chris' and c.location in
    ('Chongqing','Guangdong','Guangxi','Hubei','Jiangxi','Ningxia','Qinghai','Sichuan','Yunnan',' ')  
    and (c.ets is null or c.ets not like '%es1%') order by c.state asc, c.addtime desc)
      

  2.   

    union把两个结果集合并起来。
    合并2个语句,和做数学题差不多,提取公因式,分拆,合集。
      

  3.   


    用union all 吧,如果要去掉重复的数据,就用union吧!