Solved

Simple Query Question

Posted on 2013-05-24
1
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use Select Query to Return Results as a Form 9 58
Generate PDF from MySQL using PHP 3 71
Dynamic Table mySQL stored procedure 5 63
MySQL HA and DR solution. 5 38
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

738 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