簡體   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