缩短 sql 查询(使用 ms 访问)

Shortening an sql query(Using ms access)

我最近开始用 SQL 做更多的实验,我 运行 遇到了一个小问题。我想知道是否有更短的方式来描述这个查询,或者我需要阅读什么才能更好地理解这个问题。感谢任何帮助,因为我什至不知道如何准确描述我的问题..

我有 2 个表,每个表有 4 个值。

TableOne           TableTwo
One1                Two1
One2                Two2
One3                Two3
One4                Two4

现在我需要的是,例如,当我从 TableOne 中 select One1One3 以及从 TableTwo 中 Two2Two3 时,查询结果为全部相等的记录

所以我会得到包括以下内容的记录:

One1 and Two2
One1 and Two3
One3 and Two2
One3 and Two3

到目前为止我的逻辑是:

Where (TableOne = One1 and TableTwo = Two2) 
   or (TableOne = One1 and TableTwo = Two3)
   or (TableOne = One3 and TableTwo = Two2)
   or (TableOne = One3 and TableTwo = Two3)

我觉得 硬编码 太多了。有没有办法说 Where TableOne is 1 and Tabletwo is either 2 or 3 然后添加这些记录等等?

希望这是可以理解的。

使用in:

where TableOne in (One1, One3) and
      TableTwo in (Two2, Two3)

这遵循示例代码中的命名约定。

您还可以使用:

Where (TableOne = One1 or TableOne = One3) and (TableTwo = Two2 or TableTwo = Two3)