繁体   English   中英

带有多个子查询的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的数量,我只需要从表1中选择thisID和thisNAME。

我必须承认我在编写查询方面的工作有点超出我的深度...但是我确定Im正确吗? 有什么帮助吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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