如何在数据库中加入4个或更多表? [英] How to join 4 or more tables in the database?

查看:98
本文介绍了如何在数据库中加入4个或更多表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将3加入taqlbe并执行此操作:

I tried to make a 3 joined taqlbe and did this:

daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation " &
                              "FROM (Sector INNER JOIN Association ON Sector.SectorID=Association.SectorID)" &
                              "INNER JOIN Company ON Company.AssociationID = Association.AssociationID", con)







它起作用,因为我期待它工作,但是当我添加另一张桌子时。

以下这些集合的设置代码。




It worked as I was expecting it to work but when I added another table.
These set codes of sets below.

daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation,Product.ProductDesc,Product.RawMatDesc " & 
                            "FROM (Sector INNER JOIN Association ON Sector.SectorID=Association.SectorID)" & 
                            "(INNER JOIN Company ON Company.AssociationID = Association.AssociationID) " & 
                            " INNER JOIN Product ON Product.CompanyID = Company.CompanyID  ", con)





它停止工作并弹出一个错误,说明FROM子句有问题。因此,您可以看到,我将第二个内部联接放入括号中但仍然没有用,并再次弹出FROM子句错误。有人可以指出我在这里缺少什么吗?



It stops working and pops out an error that says something is wrong with the FROM clause. So as you can see there, I put the 2nd inner join into parenthesis but still no use and pops out the FROM clause error again. Can someone please point out what am I lacking here?

推荐答案

加入两个以上的表与两个表相同所以你需要在表中有一些错误名称,列名或语法。



通常,表在ON子句中的列出顺序与它们在FROM子句中的顺序相同。此外,我认为没有必要使用括号。



所以只需尝试类似

Joining more than two tables is the same as with two tables so you need to have some mistake in the table names, column names or syntax.

Typically the tables are listed in the ON clause in the same order as they are in the FROM clause. Also I don't see any need for the parenthesis.

So simply try something like
SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation,Product.ProductDesc,Product.RawMatDesc 
FROM Sector 
     INNER JOIN Association ON Sector.SectorID=Association.SectorID
     INNER JOIN Company ON Association.AssociationID = Company.AssociationID
     INNER JOIN Product ON Company.CompanyID = Product.CompanyID 


我让它工作了通过涂上另一个括号



I made it work by coating another parenthesis

daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation, Product.ProductDesc, Product.RawMatDesc " &
"FROM ((Sector " &
"INNER JOIN Association ON Sector.SectorID=Association.SectorID) " &
"INNER JOIN Company ON Association.AssociationID=Company.AssociationID) " &
"INNER JOIN Product ON Company.CompanyID=Product.CompanyID ", con)





感谢你的建议虽然:)如果没有你,我也不会意识到。



Thanks for your suggestion though :) If not for you I would not realize it.


这篇关于如何在数据库中加入4个或更多表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆