我将列出一些查询。输出稍后给出,接近尾声。
这个查询给了我 7 行。
SELECT
S.companyname AS supplier, S.country,
P.productid, P.productname, P.unitprice
FROM Production.Suppliers AS S
LEFT OUTER JOIN Production.Products AS P
ON S.supplierid = P.supplierid
WHERE S.country = N'Japan'
ORDER BY S.country
下一个查询与上面相同,只是 WHERE 被 AND 替换。这给出了 34 行。
SELECT
S.companyname AS supplier, S.country,
P.productid, P.productname, P.unitprice
FROM Production.Suppliers AS S
LEFT OUTER JOIN Production.Products AS P
ON S.supplierid = P.supplierid
AND S.country = N'Japan'
ORDER BY S.country
我不明白为什么第二个查询的输出如下所示。请解释。
输出 1 -
supplier country productid productname unitprice
Supplier QOVFD Japan 9 Product AOZBW 97.00
Supplier QOVFD Japan 10 Product YHXGE 31.00
Supplier QOVFD Japan 74 Product BKAZJ 10.00
Supplier QWUSF Japan 13 Product POXFU 6.00
Supplier QWUSF Japan 14 Product PWCJB 23.25
Supplier QWUSF Japan 15 Product KSZOI 15.50
Supplier XYZ Japan NULL NULL NULL
输出 2 -
supplier,country,productid,productname,unitprice
Supplier GQRCV,Australia,NULL,NULL,NULL
Supplier JNNES,Australia,NULL,NULL,NULL
Supplier UNAHG,Brazil,NULL,NULL,NULL
Supplier ERVYZ,Canada,NULL,NULL,NULL
Supplier OGLRK,Canada,NULL,NULL,NULL
Supplier XOXZA,Denmark,NULL,NULL,NULL
Supplier ELCRN,Finland,NULL,NULL,NULL
Supplier ZRYDZ,France,NULL,NULL,NULL
Supplier OAVQT,France,NULL,NULL,NULL
Supplier LVJUA,France,NULL,NULL,NULL
Supplier ZPYVS,Germany,NULL,NULL,NULL
Supplier SVIYA,Germany,NULL,NULL,NULL
Supplier TEGSC,Germany,NULL,NULL,NULL
Supplier KEREV,Italy,NULL,NULL,NULL
Supplier ZWZDM,Italy,NULL,NULL,NULL
Supplier XYZ,Japan,NULL,NULL,NULL
Supplier QWUSF,Japan,13,Product POXFU,6.00
Supplier QWUSF,Japan,14,Product PWCJB,23.25
Supplier QWUSF,Japan,15,Product KSZOI,15.50
Supplier QOVFD,Japan,9,Product AOZBW,97.00
Supplier QOVFD,Japan,10,Product YHXGE,31.00
Supplier QOVFD,Japan,74,Product BKAZJ,10.00
Supplier FNUXM,Netherlands,NULL,NULL,NULL
Supplier NZLIF,Norway,NULL,NULL,NULL
Supplier CIYNM,Singapore,NULL,NULL,NULL
Supplier EQPNC,Spain,NULL,NULL,NULL
Supplier QQYEU,Sweden,NULL,NULL,NULL
Supplier QZGUF,Sweden,NULL,NULL,NULL
Supplier BWGYE,UK,NULL,NULL,NULL
Supplier SWRXU,UK,NULL,NULL,NULL
Supplier VHQZD,USA,NULL,NULL,NULL
Supplier STUAZ,USA,NULL,NULL,NULL
Supplier JDNUG,USA,NULL,NULL,NULL
Supplier UHZRG,USA,NULL,NULL,NULL