MS Access 中的联接或子查询
当我开始这篇文章时,我查看了“相关问题”,但没有一个与我正在尝试做的事情完全相同。
如果可能的话,我希望我的查询是可更新的。
哪个更好?
SELECT foobar.foo, foobar.bar
FROM foobar
WHERE foobar.baz IN (SELECT blahwoof.baz FROM blahwoof WHERE blahwoof.blah = 'value')
或者:
SELECT foobar.foo, foobar.bar
FROM foobar INNER JOIN blahwoof ON foobar.baz = blahwoof.baz
WHERE blahwoof.blah = 'value'
编辑
我已经完全限定了上面的列名称。我还意识到我没有完全指定我只关心更新 foobar
- blahwoof
只是一个查找表。
编辑 2
基本架构如下(显然不是实际代码):
table foobar
foo Autonumber PK
bar long FK ref gleeblesnort
baz long FK ref blahwoof
table blahwoof
baz Autonumber PK
blah text --'type' designation
我最终也会从 gleeblesnort 中提取值,但这不是此查询的直接部分。
I looked at the "Related Questions" as I started this, but none of them are exactly the same as what I'm trying do.
If at all possible, I want my query to be updatable.
Which is better?
SELECT foobar.foo, foobar.bar
FROM foobar
WHERE foobar.baz IN (SELECT blahwoof.baz FROM blahwoof WHERE blahwoof.blah = 'value')
Or:
SELECT foobar.foo, foobar.bar
FROM foobar INNER JOIN blahwoof ON foobar.baz = blahwoof.baz
WHERE blahwoof.blah = 'value'
Edit
I've fully qualified the column names above. I also realized that I hadn't fully specified that it's only foobar
that I care about updating--blahwoof
is a lookup table only.
Edit 2
Bare-bones schema as follows (not actual code, obviously):
table foobar
foo Autonumber PK
bar long FK ref gleeblesnort
baz long FK ref blahwoof
table blahwoof
baz Autonumber PK
blah text --'type' designation
I'll eventually be pulling values from gleeblesnort as well, but that's not a direct part of this query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
视图的第一个版本可以在任何合理兼容的 SQL RDBMS 中更新。
The first version of the view will be updateable in any reasonably compliant SQL RDBMS.
使用内连接。它应该具有更高的性能。 IIRC,这也将是可更新的。
Use the inner join. It should be much more performant. IIRC, this will be updatable, too.
我认为它们不是同一个查询。在第一个查询中,如果您有 1 个 baz 值,则足以满足 WHERE 条件,并且您实际上意味着连接结果(baz 和 blah=value...)
(您可能需要使用 baz 的表前缀信息来使更清楚了)
I think they are not the same query. in the first query if you have 1 baz value it is enough to satisfy the WHERE condition, and you actually meant for the join results (baz and blah=value...)
(you might need to use table prefix infornt of baz to make it clearer)