#4 Error: near line 1: near "order": syntax error


#1

On this lesson I when following part 1 I got the above error. Upon using the Get Code help it was able to pass, but when I type it how I was shown to format SQL queries it doesn’t work. Why??

My code:

SELECT date(ordered_at), ROUND(sum(amount_paid), 2)
FROM orders
JOIN order_items
ON orders.id = order_items.order.id
WHERE name = ‘kale-smoothie’
GROUP BY 1
ORDER BY 1;


#2

Hello :slightly_smiling:

Just change the last point on the line… : ON orders.id = order_items.order.id

… by the underscore like this : ON orders.id = order_items.order_id


#3

That worked! Thank you, doesn’t mean I understand why though.


#4

It’s because on the join you have to indicate the field in both columns which do the join clause in this case the ‘id’ field on the orders table and the ‘orders_items’ on the order_id table.

The way you do it is using this syntax field.table, so if you put orders.id = order_items.order.id you are indicating the field ‘orders’ on id table. That’s why isn’t working.


#5

so does anyone know how to solve my problem in #4 daily revenue part 2.

Here is my code:
select date(ordered_at), round(sum(amount_paid),2) from orders join order_items on orders.id = order_items.order_id where name = ‘Kale-smoothie’ group by 1 order by 1;

Error message: filter to kale smoothie