I have the following tables: Table 1 +------------+ | id | name | +----+-------+ | 1 | Bob | | 2 | Sue | | 3 | Jim | | 4 | Jen | +----+-------+ Table 2 +------------+----------+ | id | manid | womanid | +----+-------+----------+ | 1 | 3 | 2 | +----+-------+----------+ I want to retreive the row from table 2 with the names Jim and Sue. How can I do this? Thanks!
Try this one: SELECT * FROM table2 WHERE table2.manid=(select id from table1 where name='Jim') AND table2.womanid=(select id from table1 where name='Sue'); Code (markup):
Thanks for your help, but I don't know the names when I'm doing the SQL call. I simply want to retrieve names associated with the record in table2.
Get man id: SELECT name FROM table1 WHERE id = (SELECT manid from table2 WHERE id='1'); Code (markup): Get woman id: SELECT name FROM table1 WHERE id = (SELECT womanid from table2 WHERE id='1'); Code (markup):