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

whats wrong with this query?

Status
Not open for further replies.

hotliquer

Programmer
Oct 5, 2005
7
GB
please can anyone tell me why this query brings back results that are outside of the specified dates?

SELECT DISTINCT date
FROM lehrbook_prices
JOIN lehrbook ON lehrbook_prices.product = lehrbook.product_code
WHERE date
BETWEEN '2005-09-08'
AND '2005-09-09'
AND maker = 'Ben Taylor'
OR second_maker = 'Ben Taylor'
OR assistants = 'Ben Taylor'

thanks for any help!

hopefully!
 
it's a parentheses problem

ANDs take precedence over ORs

what you have is this --

... where A and B or C or D

which is evaluated like this --

... where ( A and B ) or C or D

when what i'll bet you really want is --

... where A and ( B or C or D )

tip: whenever you mix ANDs and ORs, always use parentheses to make sure you get exactly what you want


r937.com | rudy.ca
 
Thankyou very very much! that worked a treat and taught me a great deal!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top