当前位置: 代码迷 >> PB >> SQL子查询中是否可以使用union解决方法
  详细解决方案

SQL子查询中是否可以使用union解决方法

热度:93   发布时间:2016-04-29 09:55:23.0
SQL子查询中是否可以使用union
请问SQL子查询中是否可以使用union.     例如:
        select   字段1,字段2   from   (
                select   字段1,字段2,字段3   from   表1
                union  
                select   字段1,字段2,字段3   from   表2)   nowweek
请问这个语句是否正确,请高手指点,谢谢!

------解决方案--------------------
理论上可以,你运行一下就知道了.
不过,这样会很慢的。不如简单一点:
select 字段1,字段2 from (select 字段1,字段2,字段3 from 表1)

union all

select 字段1,字段2 from (select 字段1,字段2,字段3 from 表2)
------解决方案--------------------
當然可以用。。。select f_name from (select f_name from a where f_num1= '3 ' union all select f_name from a where f_num1 = ' 6 ' ) b
  相关解决方案