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

multiple OR's and one AND 2

Status
Not open for further replies.

ivow

Programmer
Aug 6, 2002
55
CA
Hi All,
I have statement like this:

SELECT * FROM table1 WHERE lang="English" OR lang="French" OR lang="Spanish"
AND title LIKE '%" & variable & "%' ORDER BY Lang, Sort1byMan, Product,
Sort2byCurrent, Sort3byLevel

What I'd like out of this is:
everything that contains the text from 'variable' from table1 in French,
Spanish and English.
What I get:
everything from table1 in French and English, and everything that contains
the text from 'variable' only from Spanish.

How could I "fix" my sql statement to do this?


Ivo
"If it's stupid but works, it isn't stupid."
 
Try this:

SELECT * FROM table1 WHERE (lang="English" OR lang="French" OR lang="Spanish")
AND title LIKE '%" & variable & "%' ORDER BY Lang, Sort1byMan, Product,
Sort2byCurrent, Sort3byLevel

Hope this helps.
 
sweet! that was good! thanks. "If it's stupid but works, it isn't stupid."
 
Remember, unless you 'force' it by using parenthesis the order of precedence for LOGICAL operators is AND, then OR, then NOT.

Ref: See Books OnLine, Index search on "logical operators, AND".

-SQLBill
 
This works the same but is a lot easier to read.

SELECT * FROM table1
WHERE lang in ("English","French","Spanish")
AND title LIKE '%" & variable & "%'
ORDER BY Lang, Sort1byMan, Product,
Sort2byCurrent, Sort3byLevel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top