I’m using MySQL inside PHP.
I have an SQL table that looks something like this:
id | category_id | date
-----------------------------
1 | 3 | 2012-09-12
2 | 4 | 2012-10-25
3 | 3 | 2012-10-12
4 | 3 | 2012-10-02
5 | 4 | 2012-11-03
6 | 3 | 2012-11-02
I’m trying to figure out how can select all dates of the given category if at least one falls within the specified date range, otherwise select none.
For example:
If the date range is from 2012-09-01 to 2012-09-31, then the query should return all rows for category 3 and none for category 4.
Is there a way do this in a single query ?
Thanks!
You do this with a join or in clause: