简体   繁体   中英

MYSQL with multiple SUBQUERIES

Hi and thanks for reading.

SELECT DISTINCT (thisID and thisNAME) from table1 WHERE thisID IN
(SELECT id from table2 WHERE ... condtions)
OR 
(SELECT id from table3 WHERE ... different condtions)
OR 
(SELECT id from table99 WHERE ...even more conditions)

I need to perform a few SELECTS to provide a nu,ber of thisID's once I have these I need to select only thethisID and thisNAME from the table 1.

I must admit Im a little out of my depth with writing queries...but Im certain Im on the right lines? Any help please??

Your SQL is pretty close. You need to repeat the IN part and fix a few outher syntactic stuff:

SELECT DISTINCT thisID, thisNAME
from table1
WHERE thisID IN (SELECT id from table2 WHERE ... conditions) OR 
      thisID IN (SELECT id from table3 WHERE ... different conditions) OR
      thisID IN (SELECT id from table99 WHERE ...even more conditions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM