Dear Vincent, > I have 2 numeric column a,b in my table. > I want to retrieve rows which a in range > x~y, but b not in this range. So I wrote > a SQL statement > > select * from <table> where > ( a > x and a < y ) and ( b < x or b > y ) > > But wrong result returned with this > statement. Is this SQL wrong?
There is a question of logic in the relationship: if the range is x through y, does it include the values of x and y? In which case the < and > relationships need to include equality. However, you have provided very little information, and the crystal ball filter on the mail-list is due for an upgrade!? The above is not your SQL. What is? Where do x and y come from and how are the values expressed? What are the data types of the two columns, x and y? Why not list a sample answer from your current 'best effort' and use it to illustrate your statement, "wrong result"? Help us to help you! All other things being equal, consider writing the OR first (ie try to have exclusions recognised as early as possible) to improve efficiency. =dn --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php