I’m trying to join tables events and venues, however I ran into an issue whilst inner joining. This is how I did it:
$query = "SELECT e.*, v.* FROM events e WHERE start_datetime >= '$DATE_START_SELECTED' AND end_datetime < '$DATE_END_SELECTED'".
"INNER JOIN venues v ON e.VENUE_LOCATION = v.VENUE_ID";
And for some reason I have an error like this:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘INNER JOIN venues v ON e.VENUE_LOCATION = v.VENUE_ID’ at line 1
Any idea why? Thanks!
Edit:
I updated the code to look like this:
$query = "SELECT e.*, v.* FROM events e ".
"INNER JOIN venues v ON e.VENUE_LOCATION = v.VENUE_ID".
"WHERE start_datetime >= '$DATE_START_SELECTED' AND end_datetime < '$DATE_END_SELECTED'";
Only to get this error:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘start_datetime >= ‘2012-03-15 06:00:00’ AND end_datetime <
‘2012-03-16 05:59:00” at line 1
Your
INNER JOINneeds to come before theWHEREclause.E.g.,