Writing a SQL stmt with specific where conditions

Posted on 2014-08-19
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.
Question by:djpierce54
    LVL 34

    Accepted Solution

    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')
    LVL 31

    Assisted Solution

    select * from mydata
    select * from mydata
    where col3 = 't' and col4 = 'n';

    Author Closing Comment

    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

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now