Mysql:对于连接两个表的查询感到困惑

时间:2015-06-22 02:21:49

标签: mysql sql join

我有两张桌子:

仓库

  • WarehouseID
  • WCity

装运

  • 订单ID
  • WarehouseID
  • 并按ShipDate

我希望列出orderID从公司在纽约的所有仓库发货的订单。

我试过的查询

select orderID
from shipment
join shipment on warehouse.warehouseID = shipment.warehouseID
where warehouse.Wcity = "new york";

1 个答案:

答案 0 :(得分:1)

你正在做自我join而不是加入另一张桌子。请尝试以下方法:

select s.`OrderID`
from `Shipment` s
join `Warehouse` w on w.`WarehouseID` = s.`WarehouseID`
where w.`WCity` = 'new york';