简体   繁体   中英

LEFT JOIN query MYSQL does not work

I have 2 tables rtz_order and rtz_restaurant

From order I want purchaseprice from restaurant i want "restaurant_commission" both have a column called restaurant_id So i want to join these to tables and add the restaurant_commission tot the query. I have come up with this (the date part etc works, i was already using that but the query does not work since I added the join)

$sql = 'SELECT 
    order.orderpurchase,
    order.orderdate,
    order.status,
    order.restaurant_id,
    res.restaurant_commission,
    res.restaurant_id
FROM rt_order order 
    LEFT JOIN rt_restaurant res ON order.restaurant_id = res.restaurant_id
WHERE date(order.orderdate) >= date(?) AND date(order.orderdate) <= date(?) 
    AND order.restaurant_id = ? AND order.status = "completed"';

I have tried diffrent things but i do not see why this is going wrong

ORDER is a reserved keyword.

Use backtics like:

`ORDER`

Check the complete list of reserved keywords here .

NOTE : It is better to avoid reserved keywords for column names, but if you use then wrap them with backtics.

Your alias order is a MySQL reserved word .

Make it either `order` using backticks, or change the alias' name.

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