View Full Version : Query with "And" and "Or"


lcline
10-29-2001, 05:57 AM
Hello,
I have a table that has 30 + types of equipment with multiple frequencies (5 day, 10 Day, 20 Day)at which certain tasks are done. What I need is when I specify a 20 Day frequency for a specific piece of equipment is combine only the 5 Day and 10 Day and 20 Day onto one report. Below is the SQL for the query that I have tried. The problem is it gives the specific equipment along with all other non-specified with matching frenquencies.
SELECT [Main Task table].[Equipment Type], [Main Task table].Frequency
FROM [Main Task table]
WHERE ((([Main Task table].[Equipment Type])=" 9 Volt HSCL (500)") AND (([Main Task table].Frequency)="5 Days")) OR ((([Main Task table].Frequency)="10 Days")) OR ((([Main Task table].Frequency)="20 Days"));
Thanks in advance for any help provided

Pat Hartman
10-29-2001, 11:03 AM
The parentheses are improperly placed. I also eliminated the extraneous ones. You should be able to just post it back.

[Main Task table].[Equipment Type] = " 9 Volt HSCL (500)" AND ([Main Task table].Frequency = "5 Days" OR [Main Task table].Frequency = "10 Days" OR [Main Task table].Frequency = "20 Days");

A more readable version is:
[Main Task table].[Equipment Type] = " 9 Volt HSCL (500)" AND [Main Task table].Frequency IN ("5 Days", "10 Days", "20 Days");

Using the IN clause allows you to eliminate repeating the field name three times for the OR part of the test.