简体   繁体   中英

Mysql inner join error

I have the following problem, i m 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

Where clause needs to added after all the JOIN's

SELECT rentals.*, cars.tank_capacity, cars.price 
FROM rentals 
INNER JOIN cars
        ON cars.mvc_nr = rentals.mvc_nr
WHERE rentals.mvc_nr = '$mvc' AND rentals.active = 'y'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM