简体   繁体   中英

Shortening an sql query(Using ms access)

I have started to experiment more with SQL lately and I ran into a small issue. I would like to know if there is a shorter way to describe this query or what I need to read to understand this better. Any help is appreciated, since I don't even know exactly how to describe my issue..

I have 2 tables, each have 4 values.

TableOne           TableTwo
One1                Two1
One2                Two2
One3                Two3
One4                Two4

Now what I need, is when I select One1 and One3 from TableOne and Two2 and Two3 from TableTwo for example, that the query result is the records where they are all equal.

So I would get records that include:

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

My logic thus far was:

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

It seems like too much hardcoding or so to me. Is there a way to say Where TableOne is 1 and Tabletwo is either 2 or 3 then add those records and so on?

Hope this is understandable.

Use in :

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

This follows the naming convention in your sample code.

您还可以使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM