ORA-00933 UNION 与 ORDER BY】的更多相关文章

在SQL语句中,UNION关键字多用来将并列的多组查询结果(表)合并成一个结果(表),简单实例如下: SELECT [Id],[Name],[Comment] FROM [Product1] UNION SELECT [Id],[Name],[Comment] FROM [Product2] 上面的代码可以实现将从Product1和Product2两张表合并成一个表,如果您只是希望合并两张表中符合特定条件的记录抑或是合并两张表各自的前N条记录,那么您的代码可能会像下面这样写: SELECT [I…
今天有个项目出现了问题 问题原因是union和order by 的问题.关于这个问题的解决方案可以猛击下面的链接. http://blog.csdn.net/gtuu0123/article/details/5248202…
原文:http://blog.csdn.net/lwei_998/article/details/6093807 The UNION operator returns only distinct rows that appear in either result, while the UNION ALL operator returns all rows.The UNION ALL operator does not eliminate duplicate selected rows union…
  我有一个表 CREATE TABLE `test1` (  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  `name` varchar(20) NOT NULL,  `desc` varchar(100) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 (1)以下查询会报错误:[Err] 1221 - Incorrect usage of UNION and…
MySQL中union和order by是可以一起使用的,但是在使用中需要注意一些小问题,下面通过例子来说明.首先看下面的t1表. 1.如果直接用如下sql语句是会报错:Incorrect usage of UNION and ORDER BY. SELECT * FROM t1 WHERE username LIKE 'l%' ORDER BY score ASCUNIONSELECT * FROM t1 WHERE username LIKE '%m%' ORDER BY score ASC…
之前,同事在编写视图的过程中遇到这样了这个错误.我把简化后的语句整理如下: 1: select 2: '2016' as nf, 3: qxdm, 4: round(sum(tbdlmj)/10000,2) as csydmj--单位转换,2位小数 5: from dltb_2016@dblink_td_tdxz m where dlmc='城市' 6: group by m.qxdm order by m.qxdm 7:  8: union all 9:  10: select 11: '20…
[MySql union与order by] 如果您想使用ORDER BY或LIMIT子句来对全部UNION结果进行分类或限制,则应对单个地SELECT语句加圆括号,并把ORDER BY或LIMIT放到最后一个的后面. 可以在第一个SELECT语句中提供一个列别名,并在ORDER BY中参阅别名,或使用列位置在ORDER BY中参阅列. 参考:http://www.51edu.com/it/bckf/415474.html…
我在一个业务中采用了按月的分表策略,当查询的条件跨月的时候,使用了union all汇总2个表的数据,并按插入时间倒序排列.查询并不复杂,但是当执行的时候却报错了. SELECT * FROM `table_201604` ORDER BY `REPORT_TIME` DESC UNION ALL SELECT * FROM `table_201605` ORDER BY `REPORT_TIME` DESC [Err] 1221 - Incorrect usage of UNION and O…
静态专题和APP版专题(order by不起作用): [query] sql=(select sp_f13577,sp_f13576 from sp_t113 where url_1 not like '%index.shtml' and sp_f24507='1' and deleted='n' and createdate>FROM_DAYS(TO_DAYS(CURDATE())-500) order by createdate desc,createtime desc) union all…
出现这个错误的语句是酱紫的 select xxx from aaa order by xxx union all select yyy from bbb order by yyy 错误原因居然是,如果同时用了union all 和 order by,union all的子句要加上括号. 所以下面的写法就不会报错了. (select xxx from aaa order by xxx) union all (select yyy from bbb order by yyy)…