MYSQL 有多个子查询

MYSQL with multiple SUBQUERIES

您好,感谢阅读。

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)

我需要执行一些 SELECTS 以提供 thisID 的编号,一旦我有了这些,我只需要 select table 中的 thisID 和 thisNAME 1.

我必须承认我在编写查询方面有点力不从心……但我确定我的思路是对的?有什么帮助吗??

您的 SQL 非常接近。您需要重复 IN 部分并修复一些语法问题:

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);