日期:2014-05-19  浏览次数:20381 次

SQL奇怪的问题 。不大,但值得看一下
select     *     from   table1       where   1=1   order   by   日期   desc
union  
select   *   from   table2   where   1=1   order   by   日期   desc

提示union   附近有语法错误

但把两个order   by   去掉就   可以了

不知大家遇到过这个问题没有?

------解决方案--------------------
本身语法不允许,奇怪什么
------解决方案--------------------
想要排序,外面再套一层

select * from(
select * from table1 where 1=1
union
select * from table2 where 1=1)a
order by 日期 desc
------解决方案--------------------
select * from table1 where 1=1 --order by 日期 desc
union
select * from table2 where 1=1 order by 日期 desc

第一个去掉就可以了

不过是等于:
(select * from table1 where 1=1 --order by 日期 desc
union
select * from table2 where 1=1 )order by 日期 desc