简体   繁体   中英

mysql query and subquery returns all rows

I can't to build this query it returns all rows from table. I want to select only this records where catid is between 1 and 20 and only these records from interval of 30days. Seperated both queries working.

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

Whole query with subquery:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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