我有三张桌子:
ITEM
item_id
item_name
LOCATION
location_id
location_name
ITEM_LOCATION
item_id FK
location_id FK
我的查询是:
SELECT item.item_name, location.location_name
FROM item
LEFT OUTER JOIN item_location
ON item_location.item_id = item.item_id
LEFT OUTER JOIN location
ON location.location_id = item_location.location_id
WHERE item.item_id = 1
我得到项目名称的值,我没有得到location_name的值,即使连接表上存在关系。我原以为这会根据关系
返回两者的值答案 0 :(得分:0)
您使用LEFT OUTER JOIN
的原因?
请改为尝试:
SELECT item.item_name,location.location_name
从项目
INNER JOIN item_location
ON item_location.item_id = item.item_id
INNER JOIN位置
ON location.location_id = item_location.location_id
WHERE item.item_id = 1