MySQL – Returning Information in Nested Select in Outermost Select

MySQL

I've got the following working,

SELECT info1, info2 
FROM   TableA 
WHERE  id IN (SELECT xid 
              FROM   TableB 
              WHERE  userid=3 AND active=1)

which works fine, but in TableB I also have a team column which I'd like to select and return in the outermost select statement, something like this "pseudo" query, which of course doesn't work:

SELECT info1, info2, team 
FROM   TableA 
WHERE  id IN (SELECT xid, team 
              FROM   TableB 
              WHERE  userid=3 AND active=1)

I had a read around and thought maybe AS could help but I don't really know for sure. Can anybody suggest a solution? Is this even possible?

Best Answer

This is what JOINs are for:

SELECT  A.info1, 
        A.info2, 
        B.team 
FROM TableA A
INNER JOIN TableB B
    ON A.id = B.xid
WHERE B.userid = 3 
AND B.active=1
;