gpt4 book ai didi

php - 比较 id 与不同表行 mysql 的 id

转载 作者:行者123 更新时间:2023-11-29 14:15:42 26 4
gpt4 key购买 nike

所以我试图检索某人的所有兴趣,并能够列出它们。这适用于以下查询。

SELECT *,(
SELECT GROUP_CONCAT(interest_id SEPARATOR ",")
FROM people_interests
WHERE person_id = people.id
) AS interests
FROM people
WHERE id IN (
SELECT person_id
FROM people_interests
WHERE interest_id = '.$site->db->clean($_POST['showinterest_id']).'
)
ORDER BY lastname, firstname

在这个我遇到麻烦的问题中,我只想选择那些碰巧在名为 volleyballplayers 的表中拥有 ID 的人。该表只有 id、person_id、team_id 和日期字段。

SELECT *,(
SELECT GROUP_CONCAT(interest_id SEPARATOR ",")
FROM people_interests
WHERE person_id = people.id
) AS interests
FROM people
WHERE id IN (
SELECT person_id
FROM people_interests
WHERE volleyballplayers.person_id = person_id
)
ORDER BY lastname, firstname

我只是想确保只有 volleyballplayers 表中的人员出现,但我收到一条错误消息,指出 Unknown columns 'volleyballplayers.person_id' in 'where Clause'我非常确定表的名称,并且我知道该列名为 person_id。

最佳答案

尝试将其与子查询连接起来,

SELECT  *, GROUP_CONCAT(interest_id) interests
FROM people a
INNER JOIN people_interests b
ON b.person_id = a.id
INNER JOIN
(
SELECT DISTINCT person_id
FROM volleyballplayers
) c ON b.person_id = c.person_id
GROUP BY a.id
ORDER BY lastname, firstname

关于php - 比较 id 与不同表行 mysql 的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736376/

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