这是我的查询
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'
Run Code Online (Sandbox Code Playgroud)
这里我的问题是我需要从每个select语句中只获取一行.是否可以通过"限制"获取它.
根据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);
Run Code Online (Sandbox Code Playgroud)
http://dev.mysql.com/doc/refman/5.0/en/union.html