MS Access 选择相关行

发布于 2024-12-07 14:38:59 字数 236 浏览 0 评论 0原文

我有 2 个具有多对任意关系的表。在这个例子中,我们将表称为“Guys”和“Girls”。有一个联结表,其中包含相关的主键...谁与谁约会过。

如果我想找到 Guy 1 约会过的所有女孩,我会执行以下操作:在连接表上选择所有带有 girls.ID 的女孩。现在要查找女孩的姓名,我需要使用每个记录集行中的键从女孩表中选择一行

。因为我已经定义了关系,所以更简单? Access 我认为必须有一种方法来构建单个查询,我该怎么做?

I have 2 tables with a many-to-any relationship. For the example we will call the tables "Guys" and Girls" There is a junction table that contains the related primary keys...who has dated who.

If I want to find all the girls that Guy 1 has dated, I do a select on the junction table selecting all girls with guys.ID. This give me a RecordSet. Now to find the names of the girls, I need to select from the girls table a row using the key from each RecordSet row.

Isn't there an easier way? Since I've defined the relationships in Access I would think that there must be a way to build a single query. How do I do that?

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

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

发布评论

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

评论(1

晚风撩人 2024-12-14 14:38:59
SELECT girls.name 
FROM (guys 
INNER JOIN junct ON guys.guyID = junct.guyID) 
INNER JOIN girls ON junct.girlID = girls.girlID 
WHERE guys.guyID = [whatever id you're looking for]
SELECT girls.name 
FROM (guys 
INNER JOIN junct ON guys.guyID = junct.guyID) 
INNER JOIN girls ON junct.girlID = girls.girlID 
WHERE guys.guyID = [whatever id you're looking for]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文