0

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

3
  • What's going wrong? Can you supply some sample data, the result you'd expect and the result you're actually getting? Commented May 1, 2014 at 17:30
  • 1
    @Zefnus If you're going to spam a million tag edits into the system, please take the time to fix all the problems with the questions Commented Jun 11, 2014 at 17:33
  • @meagar improve or too minor, your turn. Commented Jun 11, 2014 at 17:35

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ahh,, yes... changed it to just "o" ..it works thanks!
1

Your alias order is a MySQL reserved word.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.