MySQL中的UNION ALL和LIMIT [英] UNION ALL and LIMIT in MySQL

查看:1194
本文介绍了MySQL中的UNION ALL和LIMIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我要执行此查询:

(SELECT a FROM t1 WHERE a=10 AND B=1) 
UNION ALL 
(SELECT a FROM t2 WHERE a=11 AND B=2) 
UNION ALL 
(SELECT a FROM t3 WHERE a=12 AND B=3) 
ORDER BY a LIMIT 1000;

如果"t1"中有550个结果,而"t2"中有450个结果,MySQL是否足够聪明以跳过"t3"?

Is MySQL smart enough to skip "t3" if 550 results are available in "t1" and 450 in "t2"?

我正在查看MySQL文档(

I'm looking at MySQL docs (http://dev.mysql.com/doc/refman/5.1/en/union.html) but can't seem to find the answer.

推荐答案

如UNION语法说明(http://dev.mysql.com/doc/refman/5.1/en/union.html)中指定:

As specified in UNION Syntax description (http://dev.mysql.com/doc/refman/5.1/en/union.html):

UNION的默认行为是 从中删除重复的行 结果.可选的DISTINCT关键字 除默认值外没有其他作用 因为它还指定 重复行删除.随着 可选的ALL关键字,重复行 不会发生删除,并且结果 包括所有的所有匹配行 SELECT语句.

The default behavior for UNION is that duplicate rows are removed from the result. The optional DISTINCT keyword has no effect other than the default because it also specifies duplicate-row removal. With the optional ALL keyword, duplicate-row removal does not occur and the result includes all matching rows from all the SELECT statements.

我想,这就是您的问题的答案.

I suppose, that's the answer to your question.

这篇关于MySQL中的UNION ALL和LIMIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆