[英]Comparing an id to id of different tables rows mysql
因此,我嘗試從某人檢索所有興趣,並能夠列出它們。 這適用於以下查詢。
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
我只是想確保只顯示排球運動員表中的人,但是我得到一個錯誤,說Unknown column 'volleyballplayers.person_id' in 'where clause'
中的Unknown column '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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.