Page 1 of 1

Multiple WHERE conditions in mySQL query

Posted: Sat Mar 25, 2006 9:32 am
by michlcamp
I have a table for 'orders' with a column named 'status' - after an order is placed it's marked 'paid', 'open' or 'archived'

Orders are taken online or by phone. I only want orders with order_type marked 'online'

I'm trying to retrieve all 'online' orders marked 'paid' or 'archived' but NOT 'open'

I tried this query but it doesn't work:

Code: Select all

"SELECT * FROM orders WHERE order_type='online' AND status='paid' OR status='archived'";
It brings up both 'online' orders and 'phone' orders. I only want the 'online' orders.

All suggestions appreciated.
Thanks in advance.
mc

Posted: Sat Mar 25, 2006 9:34 am
by timvw
With ( ) you can group conditions...

See the difference between "((a) and (b or c))" and (a and b or c)" ?

Posted: Sat Mar 25, 2006 9:56 am
by michlcamp
Thanks...

could you give an example?

Posted: Sat Mar 25, 2006 9:57 am
by feyd
he did. :?

Posted: Sat Mar 25, 2006 10:31 am
by michlcamp
thanks.
Solved