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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with OR and AND

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
how would I set up a query
to check to see something of this nature...

if (t1.item1=srch1 or t1.item2=srch1 or t1.item3=srch1)
and t1.item4=srch2 and t1.item5=srch3 and t1.item6=srch4;

I need it to check some OR's first, so I can have one item
I am searching for match any 3 fields, but then I must have
some successful AND's following the OR's, more than one AND.
All data is being used to check against one table. When I
try this like this, it doesn't work

select * from t1 where t1.item1=srch1 or t1.item2=srch1 or
t1.item3=srch1 and t1.item4=srch2 and t1.item5=srch3 and
t1.item6=srch4;
 
To match
at least one of (item1,item2,item3)
AND all of (item4,item5,item6)
try
Code:
SELECT * FROM t1
WHERE (t1.item1=srch1 OR t1.item2=srch1 OR t1.item3=srch1)
AND t1.item4=srch2
AND t1.item5=srch3
AND t1.item6=srch4;
To match
at least one of (item1,item2,item3)
AND at least one of (item4,item5,item6)
try
Code:
SELECT * FROM t1
WHERE (t1.item1=srch1 OR t1.item2=srch1 OR t1.item3=srch1)
AND (t1.item4=srch2 OR t1.item5=srch3 OR t1.item6=srch4);
-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top