Multiple WHERE conditions in mySQL query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Multiple WHERE conditions in mySQL query

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

With ( ) you can group conditions...

See the difference between "((a) and (b or c))" and (a and b or c)" ?
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post by michlcamp »

Thanks...

could you give an example?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

he did. :?
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post by michlcamp »

thanks.
Solved
Post Reply