有人可以解释,加入多个带别名的表吗?
我无法让代码工作......继续给我错误"无法绑定"此错误消息适用于以下内容:M.ZipCode,C.Member_ID,F.Navn,F.Navn(最后一个)。 我对SQL仍然很陌生,我知道我搞砸了Zipcode的名字。 澄清我有一个名为Zipcode的表,其中包含Zipcodes,成员在成员表中需要一个zipcode。
SELECT
m.Fornavn,
m.Efternavn,
m.Zipcode,
z.City,
c.Model,
c.Producent,
s.Navn,
s.Antal,
s.Pris
FROM Members M, Fabricator F, Cars C, Storage S, ZipCode Z
INNER JOIN Members ON Z.Zipcode = M.ZipCode AND C.Member_ID = Members.ID
INNER JOIN Cars ON F.Navn = Cars.Producent
INNER JOIN Storage ON F.Navn = Storage.Producent;
答案 0 :(得分:2)
你可能意味着
SELECT
m.Fornavn,
m.Efternavn,
m.Zipcode,
z.City,
c.Model,
c.Producent,
s.Navn,
s.Antal,
s.Pris
FROM Fabricator F
INNER JOIN Cars C ON F.Navn = C.Producent
INNER JOIN Members M ON C.Member_ID = M.ID
INNER JOIN ZipCode Z ON Z.Zipcode = M.ZipCode
INNER JOIN Storage S ON F.Navn = S.Producent
答案 1 :(得分:1)
您似乎需要以下FROM
子句:
FROM ZipCode z INNER JOIN
Members m
ON z.Zipcode = m.ZipCode INNER JOIN
Cars c
ON c.Member_ID = m.ID INNER JOIN
Fabricator f
ON f.Navn = c.Producent INNER JOIN
Storage s
ON f.Navn = s.Producent
FROM
子句中的逗号表示CROSS JOIN
- 笛卡尔积。您有多次提到的相同表。最简单的方法是学习使用正确的语法。
答案 2 :(得分:0)
FROM M,Fabricator F,Cars C,Storage S,ZipCode Z
是CROSS JOIN的简短形式,所以你必须避免使用这种表示法,据我所知它是不推荐使用的表示法