2015-11-02 96 views
0

我無法構建此查詢,它將返回表中的所有行。 我想僅選擇catid在1到20之間的這些記錄,並且只選擇這些記錄,間隔爲30天。 分離兩個查詢工作。mysql查詢和子查詢返回所有行

- SELECT * FROM `movies` WHERE uploaded >= DATE_SUB(NOW() 
- SELECT id FROM `movies` WHERE (catid BETWEEN 1 AND 20) 

與子查詢整個查詢:

SELECT * FROM `movies` WHERE uploaded >= DATE_SUB(NOW(), INTERVAL 30 DAY) IN(SELECT id FROM `movies` WHERE (catid BETWEEN 1 AND 20)) 
+0

你應該接受的答案... –

回答

4
SELECT * FROM `movies` 
WHERE uploaded >= DATE_SUB(NOW(), INTERVAL 30 DAY) 
AND catid BETWEEN 1 AND 20 
+0

運行完美,因此我不從子查詢需要:) –