开发者

Join or subquery in MS Access

开发者 https://www.devze.com 2023-02-02 21:45 出处:网络
I looked at the \"Related Questions\" as I started this, but none of them are exactly the same as what I\'m trying do.

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 开发者_StackOverflow(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.


The first version of the view will be updateable in any reasonably compliant SQL RDBMS.


Use the inner join. It should be much more performant. IIRC, this will be updatable, too.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消