MS Access 2003 query to select a record on multiple conditions

Posted on 2009-04-07
Last Modified: 2012-05-06
I need  a query to select Field1, Field2, Field3, Field4 and Field5 from every record in Table1 *except* records that meet the following criteria:
- Records in table1 that have a "0" (zero) in Field3, Field4 and Field5.
- also have the first 4 numbers of a 6 digit number in Table1.Field2 match the first 4 numbers of Table2.Field1

Both points (conditions) must be met for the record to be excluded from query results.
Question by:Muskie12
  • 3
  • 2
  • 2
LVL 119

Expert Comment

by:Rey Obrero
ID: 24089858

select *
from tablex
where (field3=0 or field4=0 or field5=0) and left(field2,4)=left(field1,4)
LVL 119

Expert Comment

by:Rey Obrero
ID: 24089865
if you aare not getting the correct results, post sample data and the expected records you want to see
LVL 15

Accepted Solution

MNelson831 earned 500 total points
ID: 24089991
2 tables Cap.

select Field1, Field2, Field3, Field4 and Field5 from Table1
where Field3 <> 0 and Field4 <> 0 and Field5 <> 0 and left(Field2,4) not in (Select left(Field1,4) From Table2)

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

LVL 119

Expert Comment

by:Rey Obrero
ID: 24090103
and I didn't see  *except* <lol>  

Author Comment

ID: 24090153
capricorn1 - I *thought* your query looked funny but figured it was a case of it being brilliant in its simiplicity so I was trying to experiment with it anyway...

MNelson831 - what do you mean "2 tables Cap."?    Also, I think since your query is selecting the records I want but using the logic of the records I want excluded, I *think* the "and"s in the first part of the WHERE need to be "or"s. I'm just playing with it now.

Author Comment

ID: 24090529
Thanks MNelson831, a couple of slight mods (repl 'and's with 'or's and remove the 'not' gave me the records I was looking for.

SELECT Table1.Field1
WHERE (((COA.JAN)<>0)) OR (((COA.FEB)<>0)) OR (((COA.MAR)<>0)) OR (((Left([Account],4)) In (Select left(Field1,4) From Table2)));
LVL 15

Expert Comment

ID: 24090640
My bad... I read the question as wanting to exclude records that met ALL conitions rather than records that met ANY condition

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form button in access 2 37
Keeping a combo box up to date for other users 5 23
Open CSV, modify and save as xls from Access 12 19
DBF to ... Converter 5 38
In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now