将嵌套的SELECT重写为INNER JOIN MySQL

时间:2016-08-01 23:50:57

标签: mysql select nested inner-join

我有一个使用WHERE IN语句的查询

(pd.to_timedelta(14487, unit='D') + pd.Timestamp('1960-1-1')).date()
#Out: 
#datetime.date(1999, 8, 31)

我尝试使用INNER JOIN重写它,但结果却少了。我做错了什么?

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)

1 个答案:

答案 0 :(得分: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