简体   繁体   English

Microsoft Access联接4个表以显示3个表中的特定值,但显示主表中的所有值

[英]Microsoft Access joining 4 tables to display specific values from 3 tables but all values from the main table

I have created a database for users to "follow" TV Shows, I need to create a form to display each show and all the relevant information to that specific show. 我已经创建了一个数据库供用户“关注”电视节目,我需要创建一个表格来显示每个节目以及该特定节目的所有相关信息。

The four tables I have are as follows: 我有四个表如下:
Shows (Main Table), 显示(主表),
Networks, 网络,
ShowGenres (Links multiple genre's to one show), ShowGenres(将多个流派链接到一个节目),
Genres. 流派。 The relationships and all fields are shown in the image below. 关系和所有字段如下图所示。

关系:

Currently I have a page which displays the following information: showID, showName, showAired, networkName, showStatus, showRuntime, showSeasons, showEpisodes, showOverview. 当前,我有一个页面,显示以下信息:showID,showName,showAired,networkName,showStatus,showRuntime,showSeasons,showEpisodes,showOverview。
Ideally i'd like to have a List box to display an array of the genre's associated with the specific show. 理想情况下,我希望有一个列表框来显示与特定节目相关的体裁的数组。 I have tried for quite a while to come up with a query to do this, the closest I managed to get showed the relevant information but added duplicate pages. 我已经尝试了很长一段时间来提出一个查询来做到这一点,我设法获得的最接近的结果显示了相关信息,但添加了重复的页面。
Here's my latest attempt: 这是我最近的尝试:

SELECT * FROM Shows A
INNER JOIN Networks B ON B.networkID = A.networkID
INNER JOIN ShowGenres C ON C.showID = A.showID
INNER JOIN Genres D ON D.genreID = C.genreID;

Any help would be appreciated, thanks in advance. 任何帮助将不胜感激,在此先感谢。

One has to appreciate the presentation level logic that can be used in conjunction with the data logic. 人们必须意识到可以与数据逻辑结合使用的表示层逻辑。 Very generically - in the 1:Many - - your query of fields that include both fields will repeat the 1 table values with each of the Many records. 非常通用-在1:Many中-您对包含两个字段的字段的查询将对Many记录的每一个重复1个表值。 That can not be altered via any query design as it is inherent in the data logic. 这不能通过任何查询设计更改,因为它是数据逻辑中固有的。

But at the presentation level you can control the display. 但是在演示级别,您可以控制显示。 Using a report - the data source can be the query - but report properties offer grouping whereby you can put the 1 field value as the group header - thus displaying just once; 使用报表-数据源可以是查询-但报表属性提供了分组,您可以将1字段值作为组标题-这样仅显示一次; and then below it list all the many records. 然后在其下面列出所有许多记录。

It is not a list box per se though depending on how creative one gets with reports/sub reports one could potentially make that style. 它本身并不是一个列表框,尽管它取决于报表/子报表的创造性,一个人可能会采用这种样式。 But in the end you must work this at the presentation level. 但是最后,您必须在表示层上进行操作。

One method is to use exists : 一种方法是使用exists

select g.*
from genres as g
where exists (select 1
              from showgenres as sg inner join
                   shows as s
                   on sg.showID = s.showID
              where sg.genreID = g.genreID and
                    s.showName = ?
             );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM