SQL SELECT 多个 INNER JOIN

发布于 2024-09-05 06:35:59 字数 1433 浏览 3 评论 0原文

它的Access数据库..

外键

我有一个Library表,其中Autnm Topic Size Cover Lang是每条记录的 实际上是一本书,有其属性,例如作者和内容。我不太确定我什至使用了正确的 JOIN .. 对于“复杂” SQL 来说相当新:)

SELECT Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
       Library.ISBN, Library.Pages, Library.PUSD, Author.ID AS [AuthorID],
       Author.Author_hebrew AS [AuthorHebrew],
       Author.Author_English AS [AuthorEnglish],
       Author.Author_Russian AS [AuthorRussian], Topic.ID AS [TopicID],
       Topic.Topic_Hebrew AS [TopicHebrew], Topic.Topic_English AS [TopicEnglish],
       Topic.Topic_Russian AS [TopicRussian], Size.Size AS [Size],
       Cover.ID AS [CoverID], Cover.Cvrtyp_Hebrew AS [CoverHebrew],
       Cover.Cvrtyp_English AS [CoverEnglish], Cover.Cvrtyp_Russian AS [CoverRussian],
       Lang.ID AS [LangID], Lang.Lang_Hebrew AS [LangHebrew],
       Lang.Lang_English AS [LangEnglish],

FROM Library INNER JOIN Author ON Library.Autnm = Author.ID
                 INNER JOIN Topic ON Library.Topic = Topic.ID
                 INNER JOIN Size ON Library.Size = Size.ID
                 INNER JOIN Cover ON Library.Cover = Cover.ID
                 INNER JOIN Lang ON Library.Lang = Lang.ID
WHERE (TopicID=13 AND LangID=1) ORDER BY LangID ASC 

编辑:插入 @Guffa 建议的括号后,我收到了一个新错误:

Too参数很少。预计 3。

its Access database..

i have a Library table, where Autnm Topic Size Cover Lang are foreign keys

each record is actually a book which has its properties such as author and stuff. i am not quite sure i am even using the correct JOIN.. quite new with "complex" SQL :)

SELECT Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
       Library.ISBN, Library.Pages, Library.PUSD, Author.ID AS [AuthorID],
       Author.Author_hebrew AS [AuthorHebrew],
       Author.Author_English AS [AuthorEnglish],
       Author.Author_Russian AS [AuthorRussian], Topic.ID AS [TopicID],
       Topic.Topic_Hebrew AS [TopicHebrew], Topic.Topic_English AS [TopicEnglish],
       Topic.Topic_Russian AS [TopicRussian], Size.Size AS [Size],
       Cover.ID AS [CoverID], Cover.Cvrtyp_Hebrew AS [CoverHebrew],
       Cover.Cvrtyp_English AS [CoverEnglish], Cover.Cvrtyp_Russian AS [CoverRussian],
       Lang.ID AS [LangID], Lang.Lang_Hebrew AS [LangHebrew],
       Lang.Lang_English AS [LangEnglish],

FROM Library INNER JOIN Author ON Library.Autnm = Author.ID
                 INNER JOIN Topic ON Library.Topic = Topic.ID
                 INNER JOIN Size ON Library.Size = Size.ID
                 INNER JOIN Cover ON Library.Cover = Cover.ID
                 INNER JOIN Lang ON Library.Lang = Lang.ID
WHERE (TopicID=13 AND LangID=1) ORDER BY LangID ASC 

Edit: After inserting the parantheses @Guffa suggested, I got a new error:

Too few parameters. Expected 3.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

清醇 2024-09-12 06:35:59

在 Access 中,如果有多个连接,则需要括号。另外,正如 Ivar 指出的那样,在字段列表中的最后一项之后有一个额外的逗号。

select
  Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
  Library.ISBN, Library.Pages, Library.PUSD, Author.ID as [AuthorID],
  Author.Author_hebrew as [AuthorHebrew], Author.Author_English as [AuthorEnglish],
  Author.Author_Russian as [AuthorRussian], Topic.ID as [TopicID],
  Topic.Topic_Hebrew as [TopicHebrew],  Topic.Topic_English as [TopicEnglish],
  Topic.Topic_Russian as [TopicRussian], Size.Size as [Size], Cover.ID as [CoverID],
  Cover.Cvrtyp_Hebrew as [CoverHebrew], Cover.Cvrtyp_English as [CoverEnglish],
  Cover.Cvrtyp_Russian as [CoverRussian], Lang.ID as [LangID],
  Lang.Lang_Hebrew as [LangHebrew], Lang.Lang_English as [LangEnglish]  
from
  (((((Library
  inner join Author on Library.Autnm = Author.ID)
  inner join Topic on Library.Topic = Topic.ID)
  inner join Size on Library.Size  = Size.ID)
  inner join Cover on Library.Cover = Cover.ID)
  inner join Lang on Library.Lang  = Lang.ID)

编辑:

错误消息“参数太少”。意味着您在查询中定义了参数,但在执行查询时不会一起发送这些参数。由于您在查询中没有使用任何参数,这意味着您在查询中拼写了一些名称错误,因此它认为它们是参数。

In Access you need parentheses if you have more than one join. Also, as Ivar pointed out, you have an extra comma after the last item in the field list.

select
  Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
  Library.ISBN, Library.Pages, Library.PUSD, Author.ID as [AuthorID],
  Author.Author_hebrew as [AuthorHebrew], Author.Author_English as [AuthorEnglish],
  Author.Author_Russian as [AuthorRussian], Topic.ID as [TopicID],
  Topic.Topic_Hebrew as [TopicHebrew],  Topic.Topic_English as [TopicEnglish],
  Topic.Topic_Russian as [TopicRussian], Size.Size as [Size], Cover.ID as [CoverID],
  Cover.Cvrtyp_Hebrew as [CoverHebrew], Cover.Cvrtyp_English as [CoverEnglish],
  Cover.Cvrtyp_Russian as [CoverRussian], Lang.ID as [LangID],
  Lang.Lang_Hebrew as [LangHebrew], Lang.Lang_English as [LangEnglish]  
from
  (((((Library
  inner join Author on Library.Autnm = Author.ID)
  inner join Topic on Library.Topic = Topic.ID)
  inner join Size on Library.Size  = Size.ID)
  inner join Cover on Library.Cover = Cover.ID)
  inner join Lang on Library.Lang  = Lang.ID)

Edit:

The error message "Too few parameters." means that you have defined parameters in the query that is not sent along when it's executed. As you don't use any parameters in the query it means that you have spelled some names in the query wrong, so that it thinks that they are parameters instead.

拥抱影子 2024-09-12 06:35:59

我对 Access 不太熟悉,因此不确定它是否接受这一点,但我首先从选择列表中删除最后一个逗号。

Lang.Lang_English AS [LangEnglish], => Lang.Lang_English AS [LangEnglish]

I'm not too familiar with Access, and therefore not sure if it accepts this, but I would start by removing the last comma from the select list.

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