John Froynse
John Froynse

Reputation: 1

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))

Upvotes: 0

Views: 34

Answers (1)

juergen d
juergen d

Reputation: 204884

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

Upvotes: 4

Related Questions