Home > Net >  Getting data from table triple join
Getting data from table triple join

Time:04-16

I have three tables: product, order and order_products. Product has 2 columns:product_id(pk) and product_sku Order has 3 columns: order_id(pk), order_datetime and order_status Order_products has 5 columns: op_id(pk), product_id(fk), order_id(fk), product_quantity and product_price.

I am trying to write an sql query that returns data from all the three tables but I get an error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order as o on op.order_id = o.order_id) on p.product_id = op.product_id) LIMIT 0' at line 2

My query is this one: select o.order_id, o.order_datetime, op.product_price ,op.product_quantity , op.product_id, p.sku, o.order_status_id from (product AS p INNER JOIN (order_products AS op INNER JOIN order as o on op.order_id = o.order_id) on p.product_id = op.product_id);

CodePudding user response:

select o.order_id, o.order_datetime, op.product_price ,
 op.product_quantity , op.product_id, p.sku, o.order_status_id 
from  product AS p 
 INNER JOIN  order_products AS op on p.product_id = op.product_id
 INNER JOIN order as o on op.order_id = o.order_id ;
  • Related