gpt4 book ai didi

mysql - 为什么我的子查询返回超过 1 行

转载 作者:行者123 更新时间:2023-11-29 13:24:04 26 4
gpt4 key购买 nike

我想要未显示的行,但出现错误子查询返回超过 1 行

这很好用;

SELECT CONCAT( P.LastName, ', ', P.FirstName ) AS Name, 
(
SELECT MP.MembershipID
FROM membershipperson MP
WHERE MP.PersonID = P.PersonID
)
AS MembershipID, PersonID
FROM `person` P

当我添加 ORDER BY 'MembershipID' 时,此操作会失败;如果我 ORDER BY 'PersonID',则此操作会失败;

SELECT CONCAT( P.LastName, ', ', P.FirstName ) AS Name, 
(
SELECT MP.MembershipID
FROM membershipperson MP
WHERE MP.PersonID = P.PersonID
)
AS MembershipID, PersonID
FROM `person` P
ORDER BY `MembershipID` ASC

如何获取包含所有 MembershipID 行的列表?

最佳答案

您可能应该使用内部联接。像这样的事情:

SELECT CONCAT( P.LastName, ', ', P.FirstName ) AS Name, MP.MembershipID AS MembershipID, PersonID
FROM person P, membershipperson MP
WHERE MP.PersonID = P.PersonID

关于mysql - 为什么我的子查询返回超过 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20380701/

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