多表连接MySQL多个外键

多表连接MySQL多个外键,mysql,sql,join,Mysql,Sql,Join,我在MySQL中使用连接时遇到了困难。我有四张桌子,都连在一起 **Order**: order_id, shop_id(fk), date, day, order_price, PK_order **Scan** : scan_id(PK), item_id, order_id(FK), stack, stack_price, price, note **Item** : item_id(PK), item_name **Shop** : shop_id(PK), shop_name 我想构

我在MySQL中使用连接时遇到了困难。我有四张桌子,都连在一起

**Order**: order_id, shop_id(fk), date, day, order_price, PK_order
**Scan** : scan_id(PK), item_id, order_id(FK), stack, stack_price, price, note
**Item** : item_id(PK), item_name
**Shop** : shop_id(PK), shop_name
我想构建一个输出如下内容的查询:

date|day|shop_name|item_name|stack|stack_price|price|note
Select
      order.date, order.day, shop.shop_name, item.item_name, scan.stack, scan.stack_price,
      scan.price, scan.note
From
      order, scan, shop, item
Join
      shop on order.shop_id = shop.shop_id
Join
      item on scan.item_id = item.item_id
我的查询如下所示:

date|day|shop_name|item_name|stack|stack_price|price|note
Select
      order.date, order.day, shop.shop_name, item.item_name, scan.stack, scan.stack_price,
      scan.price, scan.note
From
      order, scan, shop, item
Join
      shop on order.shop_id = shop.shop_id
Join
      item on scan.item_id = item.item_id
我得到错误1054:未知列。。。在“on子句”中,或其他“alias”错误

但是,当我从一个表中只选择一列时,它就可以工作了。 此查询可用于:

 select item.item_name from scan inner join item on scan.item_id = item.item_id
我认为从多个表中选择存在一些问题。。。有人能帮我吗?感谢您的每一个回复。感谢您将逗号分隔联接和内部联接结合在一起,您多次使用同一个表,这是不需要的

如果我没有错,这就是你要找的

SELECT `order`.`DATE`, 
       `order`.`day`, 
       shop.shop_name, 
       item.item_name, 
       scan.stack, 
       scan.stack_price, 
       scan.price, 
       scan.note 
FROM   `order` 
       join scan 
         ON `order`.order_id = scan.order_id 
       join shop 
         ON `order`.shop_id = shop.shop_id 
       join item 
         ON scan.item_id = item.item_id 

在MySQL中,
order
这个词很特别,所以在它周围加上记号是个好主意,除非你是按进行排序。尽管Vr46的答案是正确的——我认为——重新考虑一下“order”这个名称,就像wogsland提到的那样——“order”在任何sql中都会造成麻烦,你不会调用一个表“where”或“select”你会吗?我实际上在我的项目中不使用这个词,我只是把它从我的母语翻译成英语,这样你就可以理解:-)谢谢,它很管用,但我得到了一个空位:D我必须重新思考我的逻辑