如何使4表内连接工作(VB.NET) [英] How do I get a 4 table inner join to work (VB.NET)
问题描述
截至目前,我可以使用内部联接获得3个表进行合并,但我似乎无法找到一种方法来将4+表内部连接起来。
这是我的代码:
As of right now I can get 3 tables to merge using an inner join, but I can not seem to find a way to get 4+ tables inner joined.
Here is my code:
Dim sqlcon As New SqlConnection("sqlstring")
Dim sqladapt As New SqlDataAdapter("Select * From profile inner join (cemeteries inner join cemetery_reference on cemeteries.Cemetery_ID = cemetery_reference.Cemetery_ID) on Profile.Individual_ID = Cemeteries.Individual_ID", sqlcon)
sqlcon.Open()
sqladapt.SelectCommand.ExecuteNonQuery()
Dim DT As New DataTable
sqladapt.Fill(DT)
DataGridView1.DataSource = DT
sqlcon.Close()
我一直收到语法错误
我尝试了什么:
我从单词之后尝试过双括号,但是,我仍然得到相同的语法错误。
I keep getting "incorrect syntax on"
What I have tried:
I have tried double parenthesis after the word from, however, I am still getting the same syntax error.
推荐答案
您没有提供有关DBMS的信息。然而......
在单个查询中可以加入的表的数量取决于DBMS ...
典型查询看起来例如:
You didn't provide information about DBMS. Nevertheless...
The number of tables available to join within single query depends on DBMS...
A "typical" query looks like:
SELECT A.<List_Of_Fields>, B.<List_Of_Fields>, C.<List_Of_Fields>, D.<List_Of_Fields>
FROM Table1 AS A
INNER JOIN Table2 AS B ON A.PrimaryKey = B.ForeignKey
INNER JOIN Table3 AS C ON B.PrimaryKey = C.ForeignKey
INNER JOIN Table4 AS D ON C.PrimaryKey = D.ForeignKey
几种类型的连接。请参阅: SQL连接的可视化表示 [ ^ ]
详情请见:
MS SQL Server:查询加入 [ ^ ]
MS Access:加入表和查询 - 访问 [ ^ ]
There's few types of joins. See: Visual Representation of SQL Joins[^]
For further details, please see:
MS SQL Server: Querying with Joins[^]
MS Access: Join tables and queries - Access[^]
您应该在SqlManagement中尝试SQL,以便更快地进行SQL调试! ;)
无论如何,我立即发现一个bu(可能还有更多......)
选择*来自个人资料内部联接(公墓内部联接...
应该是,而不是
选择*来自个人资料内部加入(从墓地内连接中选择* ...
you should try your SQL in SqlManagement, for faster SQL debugging! ;)
At any rate I immediatelyu spoted one bu (there might be more ...)
Select * From profile inner join (cemeteries inner join ...
should be, instead
Select * From profile inner join (select * from cemeteries inner join ...
这篇关于如何使4表内连接工作(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!