mysql in union all,MySQL中的UNION ALL和LIMIT

Let's say I want to perform this query:

(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;

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

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.

解决方案

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值