I was wondering if it's possible to select some records from the database that have at least 3 records matching the query?
For example. I currently have a course which has 20 different locations and all have 3 dates:
Course 1: location Amsterdam dates: 01-09-2013 - 03-09-2013 - 02-10-2013
Course 2: location Amsterdam dates: 10-10-2013 - 11-10-2013 - 12-10-2013
I have the dates saved seperately in the database. Now when I select the dates of today and higher I only get the last date of course 1 (the first of course 2). That isn't what I want.
I want it to check whether the first two dates also match the statement and then it can select the first date. So in this example I only want the second course to be selected.
This is the query I have:
$query = "SELECT locaties_datum.id, locaties_datum.cursus_id,
locaties_datum.locatie_id, locaties_datum.van, locaties_datum.code,
locaties.plaats, locaties.link FROM locaties, locaties_datum WHERE 1 = 1 AND
locaties_datum.locatie_id = locaties.locatie_id AND
locaties_datum.van > '". strtotime("now") ."' AND
locaties.active = '1' AND
locaties_datum.cursus_id = '9' AND
locaties.locatie_id = '71'
GROUP BY locaties_datum.code
ORDER BY locaties_datum.van ASC ";
Is it possible to do what I want?