Page 1 of 1

[SOLVED]trouble with OR in query

Posted: Mon Apr 10, 2006 4:18 am
by rsmarsha

Code: Select all

select q from orders where status='proc' OR status='proc2';
Is this the correct way to use OR in queries? As it doesn't seem to show the right results.

Posted: Mon Apr 10, 2006 4:30 am
by Oren
Well, I don't see anything wrong here. Does anyone else see anything?

P.S Please post some more code so we can help you.

Posted: Mon Apr 10, 2006 4:44 am
by rsmarsha
does adding an AND after that change the or part?

Posted: Mon Apr 10, 2006 6:43 am
by timvw
Have you even bothered to try it?

Make yourself a table with one INTEGER column.
INSERT values 1, 2 and 3.
Now SELECT with possible combinations of OR and AND (and draw your own conclusions).


Anyway, any SQL book would explain that the order of precedence of OR and AND is the same.
If you want to change that you have to use ( ) to group, eg: http://www.w3schools.com/sql/sql_and_or.asp.

Posted: Mon Apr 10, 2006 8:02 am
by rsmarsha
Yeah thanks, i'd tried that didn't seem to work last time. Will look into that page and try it again.