数据未显示在 SQL 中
我有一个非常简单的问题,但我无法弄清楚,因为我是 SQL 世界的新手。这就是我尝试从 SQL 脚本中提取数据时的显示方式。
SUPPLIERID PRODUCTID DESCRIPTION SUPPLIERID
- - - 1
- - - 4
- - - 3
- - - 2
2A 1 Metal Piece -
3A 2 Plastic Piece -
4A 3 Hinges -
5A 4 Hooks -
这是我的代码,
select "PRODUCT1"."SUPPLIERID" as "SUPPLIERID",
"PRODUCT1"."PRODUCTID" as "PRODUCTID",
"PRODUCT1"."DESCRIPTION" as "DESCRIPTION",
"SUPPLIER"."SUPPLIERID" as "SUPPLIERID"
FROM "SUPPLIER"
FULL OUTER JOIN PRODUCT1
ON supplier.supplierid = product1.supplierid
如果我执行左连接或右连接,我只会得到一列信息。如何让所有列填满 4 行?
I have a very simple problem, but I can't figure it out since Im new to the SQL world. This is how my data is appearing when trying to pull it from a SQL script.
SUPPLIERID PRODUCTID DESCRIPTION SUPPLIERID
- - - 1
- - - 4
- - - 3
- - - 2
2A 1 Metal Piece -
3A 2 Plastic Piece -
4A 3 Hinges -
5A 4 Hooks -
This is my code
select "PRODUCT1"."SUPPLIERID" as "SUPPLIERID",
"PRODUCT1"."PRODUCTID" as "PRODUCTID",
"PRODUCT1"."DESCRIPTION" as "DESCRIPTION",
"SUPPLIER"."SUPPLIERID" as "SUPPLIERID"
FROM "SUPPLIER"
FULL OUTER JOIN PRODUCT1
ON supplier.supplierid = product1.supplierid
if i do a LEFT or RIGHT JOIN, I only get one column of information. How can I get all the columns to fill out in 4 rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
product1.supplierid
不与supplier.supplierid
匹配。因此,行之间没有发生真正的连接。因此您将获得每个表的完整副本。
您尝试将 1, 2, 3, 4 与 2A, 3A, 4A, 5A 匹配(它们不匹配)
您要么加入错误的列(也许您想要
supplier.supplierid
与product1.prdoductid
),或者您的表格未正确关联。Your
product1.supplierid
does not match thesupplier.supplierid
.So there is no real joining happening between rows.. So you get a full copy of each table.
you try to match 1, 2, 3, 4 with 2A, 3A, 4A, 5A (they do not match)
You are either joining the wrong columns (maybe you want
supplier.supplierid
withproduct1.prdoductid
) or you tables are not correctly related..供应商 ID 不匹配。如果“1A”应该匹配“1”,那么您应该这样做(SQL Server):
但是只有当您确定“1A”应该匹配“1”时,您才应该这样做。如果不是,那么它们确实不应该匹配,这就是为什么您通过使用
FULL OUTER JOIN
获得该结果。The supplier ID does not match. If "1A" should match "1" then you should do this (SQL Server):
But you should only do this if you KNOW FOR SURE "1A" should match "1". If you're not, then they really should not match, and that's why you get that result by using
FULL OUTER JOIN
.