Select Query

M

margaret

So I have the following query ...

SELECT Code.CODE, year.yearend, [account information].ACCOUNT, [account
information].MINOR, [account information].minor1, [account
information].Supplemental, [lybbal]+[lytot] AS lastytot, year.LYEAR,
year.Byear, year.Ayear, [account information].acctname, [account
information].MAJOR, [cybbal]+[cytot] AS currentytot
FROM [year], Code INNER JOIN [account information] ON Code.MINOR = [account
information].MINOR
WHERE (((Code.CODE)=17 Or (Code.CODE)=18 Or (Code.CODE)=19 Or (Code.CODE)=20
Or (Code.CODE)=22)) OR ((([account information].ACCOUNT)="005150900"));

I need it to select only the codes 17, 18, 19 or 20 and also select on the
account number 005150900. However, it's not selecting the account number.
Is there some other way that I need to write this?
 
G

ghetto_banjo

so you want codes 17 through 20 ONLY for Account 005150900??


if that is correct, you want to change that last OR to an AND.


in shorthand...

Where (code = 17 OR code = 18 OR code = 19.....) AND (Account =
005150900)
 
C

Chris

You need AND instead of OR between the codes and account. You want the code
to be any of those values and you want just that one account, right?
 
J

John W. Vinson

I need it to select only the codes 17, 18, 19 or 20 and also select on the
account number 005150900. However, it's not selecting the account number.
Is there some other way that I need to write this?

As noted, you need AND rather than OR. This can be confusing; the AND and OR
Boolean algebra operators *look* like English language conjunctions but they
work differently!

You can simplify the code a bit by using the IN() construct rather than
multiple OR's: try

SELECT Code.CODE, year.yearend, [account information].ACCOUNT, [account
information].MINOR, [account information].minor1, [account
information].Supplemental, [lybbal]+[lytot] AS lastytot, year.LYEAR,
year.Byear, year.Ayear, [account information].acctname, [account
information].MAJOR, [cybbal]+[cytot] AS currentytot
FROM [year], Code INNER JOIN [account information]
ON Code.MINOR = [account information].MINOR
WHERE Code.CODE IN (17,18,19,20,22) AND
[account information].ACCOUNT="005150900";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top