使用表本身的列作为查找行源查询条件
在表的设计视图的“查找”选项卡中,我输入“行源”查询。在指定 where
条件时,是否有某种方法可以引用表本身的列?比如说,
select [footable].[foreign] from [footable] where [footable].[id] = [self].id;
我在这一点上就一直很困惑。
编辑:为了通过示例进行说明,假设我当前正在编辑的表的名称为 bartable
,并且我正在为其名为 的列之一的下拉列表创建一个行源>巴兹。在该下拉列表中,我想显示
select [foreign] from [footable] inside join [bartable] on [footable].[id]=[bartable].[id]
的行,但不是所有 使用 bartable
的所有行进行连接的结果 - 相反,使用 bartable
中的 id
值 > 当前正在使用下拉菜单的行显示。因此,如果用户单击 baz
列中 bartable
行的下拉列表,并且该行的 id
为 23,它将显示所有[footable].[foreign]
其中对应的 [footable].[id]
是 23。
我希望这更清楚。
In the design view of a table, in the Lookup tab, I'm entering the Row Source query. Is there some way to refer to the columns of the table itself when specifying a where
condition? For example,
select [footable].[foreign] from [footable] where [footable].[id] = [self].id;
I've long been confused on this point.
Edit: to clarify with an example, let's say that the table that I'm currently editing has the name bartable
, and I'm creating a row source for the dropdown for one of its columns called baz
. In that dropdown I want to show the rows of select [foreign] from [footable] inner join [bartable] on [footable].[id]=[bartable].[id]
, but not to all results of that join using all rows of bartable
- rather, using the id
value from the bartable
row for which the dropdown is currently being displayed. So if the user clicked the dropdown for a bartable
row in the baz
column, and that row had an id
of 23, it would show all [footable].[foreign]
where their corresponding [footable].[id]
is 23.
I hope that's more clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想比较同一列,它会给你所有行......
这种类型的条件或
where 1=1
没有区别,请检查您到底想在那里放置什么条件。
或者,如果您从其他来源获得所需的
id
,则相应地评论或编辑您的问题。If you want to compare same column it will give you all rows...
there is no difference in this type of condition or
where 1=1
please check what condition exectly you want to put there..
or if from other source you are getting desired
id
then comment or edit your question accordingly..我刚刚来到此页面寻找同一问题的答案。
首先,对问题进行一些澄清(因为似乎有些混乱)。您有一个 Bar 表,它与 Foo 表具有外键关系。当您单击 Bar 表中的“baz”列时,您会看到一个下拉列表,其中显示 Foo 表中的每一行。您不想显示 Foo 表中的每一行;您想要显示根据条形表行中已有的某些信息选择的行的某些子集。
就我而言,我想这样做是因为 Bar 和 Foo 都与第三个表 Quux 具有外键关系。当我使用 Bar 的“baz”列中的下拉菜单时,我只需要 Foo 中链接到 Quux 中与 Bar 中的行链接到的同一行的行。
这在 Access 2007 中对我有用:
I just came to this page looking for an answer to the same question.
First, some clarification of the question (since there seems to be some confusion). You have a Bar Table that has a foreign key relationship to a Foo Table. When you click on the "baz" column in the Bar Table, you get a drop-down showing every row in the Foo Table. You don't want to show every row in the Foo Table; you want to show some subset of those rows selected according to some piece of information you already have in the Bar Table row.
In my case, I wanted to do this because both Bar and Foo have a foreign key relationship to a third table, Quux. When I use the drop-down in the "baz" column of Bar, I want only the rows in Foo that link to the same row in Quux that the row in Bar links to.
This worked for me in Access 2007:
使用“CurrentRecord”属性,例如
“bartable”是您在查找选项卡中输入“行源”查询的表
use the "CurrentRecord" property, e.g.
"bartable" is the table where you enter the "Row Source" query in the lookup tab