SQL 多重连接语句 [英] SQL multiple join statement

查看:38
本文介绍了SQL 多重连接语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 SQL 语句中只有一个内连接时,它运行良好.我尝试加入第二个表,现在我收到一条错误消息,指出存在语法错误(缺少运算符).这里有什么问题?

When I had only one inner join in my SQL statement, it worked perfectly. I tried joining a second table, and now I am getting an error that says there is a syntax error (missing operator). What is wrong here?

adsFormView.SelectCommand = "SELECT * FROM [tableCourse] INNER JOIN [tableGrade] ON [tableCourse].[grading] = [tableGrade].[id] INNER JOIN [tableCourseType] ON [tableCourse].[course_type] = [tableCourseType].[id] WHERE [prefix]='" & myPrefix & "' AND [course_number]='" & myCourseNum & "'"

推荐答案

对于多表连接,你必须将额外的连接嵌套在括号中:

For multi-table joins, you have to nest the extra joins in brackets:

SELECT ...
FROM ((origintable
JOIN jointable1 ON ...)
JOIN jointable2 ON ...)
JOIN jointable3 ON ...

基本上,对于您在第一个之后加入的每个额外表,您需要在原始 'FROM' 表之前使用一个括号,并在匹配的 JOIN 'on' 子句上使用一个右括号.

basically, for every extra table you join past the first, you need a bracket before the original 'FROM' table, and a closing bracket on the matching JOIN 'on' clause.

这篇关于SQL 多重连接语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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