Where clause stopped working

61 Views Asked by At

I have this code that (without the WHERE, was working) How do I get it to work with the WHERE clause ?

I just need it to only list lines that is current and max 2 years ahead.

$SQL = "SELECT ";
$SQL .= "SUM(Bookings.Spots) as SUMSPOT, Trips.ID, Bookings.FK_ID, Trips.MaxSpots, ";   
$SQL .= "Trips.Tripnr, Trips.StartDate, Trips.EndDate, Trips.StartLocation, ";
$SQL .= "Trips.DestinationDK, Trips.PricePerSpot "; 
$SQL .= "FROM Trips WHERE Trips.EndDate >= NOW() AND Trips.EndDate < DATE_ADD(NOW(), INTERVAL 2 YEAR) ";
$SQL .= "LEFT JOIN Bookings on Bookings.FK_ID = Trips.ID ";
$SQL .= "GROUP BY Trips.ID, Bookings.FK_ID ORDER BY Trips.StartDate ASC ";      
1

There are 1 best solutions below

1
On BEST ANSWER

You need to add the WHERE clause after the LEFT JOIN and before the GROUP tag.

You can check the documentation here for more answers as to where you can put which keyword.