Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Query Question

Posted on 2013-05-24
1
Medium Priority
?
188 Views
Last Modified: 2013-07-03
This is driving me crazy.  I am trying to select all records except for ones that match a certain criteria. Here's some set up:

Here's a sample of a table I'm working with:
Acct              Uniq
02002150B   225
02002150C   225
02002143A   222

Let's say I want to select everything where Acct does not equal 02002150B and Uniq does not equal 225.  I write a query like this:

SELECT * from something where  (Acct != '02002150B' AND Uniq != '225' )

If I run this query, the results returned are as follows:
Acct              Uniq
02002143A   222

Both accounts with the Uniq value of 225 are missing even though I requested a specific Acct number.

What's driving me crazy is that if I were to switch from != to =, the query returns only one result, which is exactly what I would expect it to do.

How can I write a query to return only these results?:
Acct               Uniq
02002150C   225
02002143A   222

Thanks for reading.  I appreciate your time.
0
Comment
Question by:thedeal56
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 39196056
You can use:
WHERE Not (Acct = '02002150B' AND Uniq = '225' )

Open in new window

which is the same as
WHERE (Acct != '02002150B' OR Uniq != '225' )

Open in new window

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
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
Course of the Month10 days, 23 hours left to enroll

886 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