gpt4 book ai didi

MySQL联合+限制

转载 作者:太空宇宙 更新时间:2023-11-03 10:22:43 31 4
gpt4 key购买 nike

这是我的查询

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'

我的问题是我只需要从每个选择语句中获取一行。是否可以通过“limit”获取。

最佳答案

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

(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

关于MySQL联合+限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9749050/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com