Jordan Davis Jordan Davis - 7 months ago 16
SQL Question

select statement within select

I have a

manage
column in my
user
table which contains a string
'2','3','4','5','6'
, these numbers reference the
user.id
's that the user "manages" .

STATMENT:

SELECT * FROM user WHERE id IN(SELECT manage FROM user WHERE id = 1)


Question: Why is my statement returning nothing?

Answer

You could create a new table user_manages, which contains two columns: manager_id and user_id. Create a new record in the table for each user a manager manages. Then you could develop a join between the two tables.

SELECT user.* FROM user_manages
INNER JOIN user ON user.id = user_manages.user_id
WHERE user_manages.manager_id = 1
Comments