2016-08-01 59 views
0

我有使用查詢凡在聲明改寫嵌套SELECT作爲INNER JOIN MySQL的

SELECT DISTINCT(col) 
FROM tab1 
WHERE id>71 AND id<5073 
AND col IN (SELECT DISTINCT(col) FROM tab0 WHERE id>55 AND id<320) 

我試着用INNER JOIN重寫它,但我得到的結果越少。我究竟做錯了什麼?

SELECT DISTINCT(t1.col) 
FROM tab1 as t1 
    INNER JOIN (
     SELECT DISTINCT(col) 
     FROM tab0 WHERE id>55 AND id<320 
    ) AS t0o ON t1.col = t0o.col 
WHERE t1.id>71 AND t1.id<5073 
+0

第二查詢有限制的't1.col = t0o.col'是第一次查詢沒有 – bernie

+0

只是要問,爲什麼你需要加入一個表..做什麼結果,你需要 –

+0

謝謝,這是一個錯字,解決了它:) – pedmillon

回答

1
SELECT distinct a.col 
FROM tab1 AS a 
JOIN tab0 AS b 
WHERE a.id > 71 AND a.id < 5073 
AND b.id > 55 AND b.id < 320 
AND a.col = b.col