[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Writing a SQL stmt with specific where conditions

Posted on 2014-08-19
3
Medium Priority
?
134 Views
Last Modified: 2014-08-20
I am drawing a blank on this.
I want to return a recordset where I have two conditions to be met.
Here is my data
Col1   col2   col3   col4
  1        n        t         p
  2        n        r         g
  3        n        r         n
  4        o        t          x
  5        o        t          n

OK I want to return all records except for record 5 where col3=t and col4=n
I require all the other columns to be returned.  I cannot reference Col1 in the where clause
Maybe I need something like a union which I do not know the syntax.
0
Comment
Question by:djpierce54
3 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 1600 total points
ID: 40271395
Not sure if this is what you're looking for but...

SELECT Col1, Col2, Col3, Col4
FROM myTable
WHERE NOT (Col3 = 't' AND Col4 = 'n')
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 400 total points
ID: 40272548
select * from mydata
except
select * from mydata
where col3 = 't' and col4 = 'n';
0
 

Author Closing Comment

by:djpierce54
ID: 40273733
Brian your answer best fit my needs as the actual query I had contains numerous joins with other tables and your's was the easiest to implement.
I could have used awking00 solution also but the select would be far more complex and I have a huge dataset to return.  The additional Select would degrade performance
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

834 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