?
Solved

Using multiple AND's and OR's

Posted on 2012-08-15
1
Medium Priority
?
475 Views
Last Modified: 2012-08-15
Hi,

I have the following query which basically, I want it to do the following:

select the field tblhostingaddons where the status is pending and the hostingid is 1
then
select one that has either the addonid 1 or the addonid 2.

The conditions that the status is pending and the hostingid is 1 must be there, but the condition for addonid can be either 1 or 2.

This is my query:

"SELECT id FROM tblhostingaddons WHERE status='Pending' AND hostingid='1' AND addonid=1 OR addonid =2"

However, it's not following my conditions that the status must be pending. It's choosing one where the status isn't pending which is wrong.

Any ideas where I'm going wrong here?
0
Comment
Question by:rvcw
1 Comment
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 38298643
Try grouping the addonid ...

"SELECT id FROM tblhostingaddons WHERE status='Pending' AND hostingid='1' AND (addonid=1 OR addonid =2)"

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question