Reputation: 1274
So I am trying to retrieve all interests from someone, and be able to list them. This works with the following query.
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
In this one which I am having trouble with, I want to select only those who happen to have their id in the table named volleyballplayers
. The table just has an id, person_id, team_id, and date fields.
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
I just want to make sure that only the people who are in the volleyballplayers table show up, but I am getting an error saying that Unknown column 'volleyballplayers.person_id' in 'where clause'
although I am quite sure of the name of table and I know the column is named person_id.
Upvotes: 0
Views: 77
Reputation: 263733
Try to join it with a subquery,
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
Upvotes: 1