首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL联合+限制

问MySQL联合+限制
EN

Stack Overflow用户
提问于 2012-03-17 18:03:22
回答 1查看 63关注 0票数 0

这是我的问题

代码语言:javascript
复制
select PhoneNumber as _data,PhoneType as _type from contact_phonenumbers where ContactID = 3 and Type = 'R' and PT = 'M' 
union 
SELECT EmailID,Type  from contact_emails where ContactID = 3 and Type = 'P' 
UNION
SELECT EmailID,Type from contact_emails where ContactID = 3 and Type = 'O' 

在这里,我的问题是我只需要从每个select语句中提取一行。是否可以通过"limit“来获取它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-17 18:06:40

根据MySQL网站,您可以像这样对单个选择应用限制

代码语言:javascript
复制
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);

http://dev.mysql.com/doc/refman/5.0/en/union.html

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9749050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档