Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

And/Or Query

Status
Not open for further replies.

isorders

IS-IT--Management
Dec 6, 2001
102
US
I have cobbled together a query
select * where ID1 OR ID2 OR ID3 = 5
but I can't get the query
select * where name="Test" AND (ID1 OR ID2 OR ID3=5).
I can't get the AND filter to work the results of the ID OR Filter.
Thanks!
 
You should change the OR expression to the following:

(ID1=5 OR ID2=5 OR ID3=5).


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Sorry I was abbreviating....it is setup like that.
Select * From tbl WHERE tbl.Name="Test" AND (tbl.ID1=5 OR tbl.ID2=5 OR tbl.ID3=5).
I want to find all of the records where the Name is Test and the ID is 5 in any of the 3 ID Fields.
 
Try changing your WHERE clause like so:

WHERE (((tbl.Name)="Test") AND ((tbl.ID1)=5)) OR (((tbl.ID2)=5)) OR (((tbl.ID3)=5));

 
Sorry, I think you meant that you want to select all those records named test with ID 5. The WHERE clause should be:

WHERE (((tbl.Name)="Test") AND ((tbl.ID1)=5)) OR (((tbl.Name)="Test") AND ((tbl.ID2)=5)) OR (((tbl.Name)="Test") AND ((tbl.ID3)=5));

If you only put "Test" in the Criteria once it'll return "Test" and ID1=5 and the rest will be ID2=5 and ID3=5 regardless of whether or not the Name is Test.

Hope this helps!
 
Select *
From tbl
Where Name="Test" AND (ID1=5 OR ID2=5 OR ID3=5)

This should work fine. Writing the Name criteria with each ID field is unnecessary if you use the parentheses. Make sure your table has rows that do and don't meet this criteria and run it again.
 
Yes, I didn't realize that but JonFer is right. The query in design view is deceptive. The WHERE clause works just as well in this form:

WHERE (((TableTest.Name)="test") AND (TableTest.ID1=5 OR TableTest.ID2=5 OR TableTest.ID3=5));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top