Comparing an id to id of different tables rows mysql

Posted by jett on Stack Overflow See other posts from Stack Overflow or by jett
Published on 2012-10-04T21:36:00Z Indexed on 2012/10/04 21:37 UTC
Read the original article Hit count: 213

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql