我有4个表:order,order_product,product,product_description。
我试图从这四个表中获得以下colomuns: 作者(product_description),名称(product_description),型号(产品), order_id (订单) 在order.order_status_id = 1
的时候我正在使用此查询:
SELECT product_description.name AS name
product_description.author AS author
product.model AS model
`order`.`order_id` AS `order_id`
FROM product_description
INNER JOIN product_description ON product.product_id=product_descripton.product_id
INNER JOIN product ON `order`.product_id=product.product_id
INNER JOIN `order` ON `order_product`.`order_id`=`order`.`order_id`
WHERE `order`.`order_status_id`=1
但它不起作用。 有什么建议吗?
谢谢!
答案 0 :(得分:3)
你忘记了select中的逗号并且你加入了同一个表两次,并且你在其中一个内连接中有一个拼写错误,这应该有效:
SELECT product_description.name AS name,
product_description.author AS author,
product.model AS model,
`order`.`order_id` AS `order_id`
FROM product_description
INNER JOIN product ON product_description.product_id=product.product_id
INNER JOIN order_product ON order_product.product_id=product.product_id
INNER JOIN `order` ON `order`.order_id=order_product.order_id
WHERE `order`.order_status_id=1