I have the following problem, im trying to execute and learn about joins as stipulated in W3schools here
Im trying to use a join to get data from 2 tables. Im using the following query:
SELECT rentals.*, cars.tank_capacity, cars.price FROM rentals WHERE mvc_nr = '$mvc' AND active = 'y' INNER JOIN cars ON cars.mvc_nr = rentals.mvc_nr"; both column mvc_nr and active exists in both tables and values correspond.
The value of $mvc = 123456789 in both tables
When I run the query without the WHERE clause I get all the data back and the query executes successfully, but as soon as I add that WHERE clause I get the error
The error reads: syntax error near 'INNER JOIN cars ON cars.mvc_nr = rentals.mvc_nr'
Any help appreciated
SELECT rentals.*, cars.tank_capacity, cars.price FROM rentals INNER JOIN cars ON cars.mvc_nr = rentals.mvc_nr WHERE rental.mvc_nr = '$mvc' AND active = 'y'INNER JOINis adding another table to the table you are selectingFROM. The table(s) you are selectingFROMshould always come before theWHEREpart of the query or else the query won't know the columns you are referencing in the where clause. So it'sSELECT [columns] FROM [table] JOIN [table2] ON [foreign columns] WHERE [where something is true].