我有 3 张桌子。
第一:
商店( StoreID, Name)
第二个:
Store_Items( StoreID, ItemID)
第三个:
项目( ItemID, Name, Price)
我怎样才能写一个语句,得到all StoreID和all names和all items for each StoreID?
我应该使用加入还是什么?
我有 3 张桌子。
第一:
商店( StoreID, Name)
第二个:
Store_Items( StoreID, ItemID)
第三个:
项目( ItemID, Name, Price)
我怎样才能写一个语句,得到all StoreID和all names和all items for each StoreID?
我应该使用加入还是什么?
select *
from Store as S
left outer join Store_Items as SI on SI.StoreID = S.StoreID
left outer join Items as I on I.ItemID = SI.ItemID
select s.storeid, s.name, si.itemid, i.name, i.price
from store s
left join store_item si on si.storeid = s.storeid
left join item i on i.itemid = store.itemid
是的,您应该大致这样加入表格
SELECT * FROM `firstone`
LEFT OUTER JOIN `secondone`
ON firstone.StoreId = secondone.StoreID
LEFT OUTER JOIN `thirdone`
ON secondone.ItemID = thirdone.ItemID