数据未显示在 SQL 中

发布于 2024-11-01 06:13:42 字数 816 浏览 7 评论 0原文

我有一个非常简单的问题,但我无法弄清楚,因为我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花想c 2024-11-08 06:13:42

您的product1.supplieridsupplier.supplierid匹配。

因此,行之间没有发生真正的连接。因此您将获得每个表的完整副本。

您尝试将 1, 2, 3, 42A, 3A, 4A, 5A 匹配(它们不匹配

您要么加入错误的列(也许您想要 supplier.supplieridproduct1.prdoductid),或者您的表格未正确关联。

Your product1.supplierid does not match the supplier.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 with product1.prdoductid) or you tables are not correctly related..

娇妻 2024-11-08 06:13:42

供应商 ID 不匹配。如果“1A”应该匹配“1”,那么您应该这样做(SQL Server):

select   "PRODUCT1"."SUPPLIERID" as "SUPPLIERID",        
         "PRODUCT1"."PRODUCTID" as "PRODUCTID",
         "PRODUCT1"."DESCRIPTION" as "DESCRIPTION",
         "SUPPLIER"."SUPPLIERID" as "SUPPLIERID" 
FROM "SUPPLIER" INNER JOIN PRODUCT1
ON supplier.supplierid + 'A' = product1.supplierid

但是只有当您确定“1A”应该匹配“1”时,您才应该这样做。如果不是,那么它们确实不应该匹配,这就是为什么您通过使用 FULL OUTER JOIN 获得该结果。

The supplier ID does not match. If "1A" should match "1" then you should do this (SQL Server):

select   "PRODUCT1"."SUPPLIERID" as "SUPPLIERID",        
         "PRODUCT1"."PRODUCTID" as "PRODUCTID",
         "PRODUCT1"."DESCRIPTION" as "DESCRIPTION",
         "SUPPLIER"."SUPPLIERID" as "SUPPLIERID" 
FROM "SUPPLIER" INNER JOIN PRODUCT1
ON supplier.supplierid + 'A' = product1.supplierid

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文