[SOLVED]trouble with OR in query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

[SOLVED]trouble with OR in query

Post 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.
Last edited by rsmarsha on Mon Apr 10, 2006 8:02 am, edited 1 time in total.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

does adding an AND after that change the or part?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Yeah thanks, i'd tried that didn't seem to work last time. Will look into that page and try it again.
Post Reply