Exclude records from list where one record equals a particular value

  • Here's an example list. I need to exclude this MRN from my query because it contains the value 250.

    MRN ICD9Code

    123456 245

    123456 432

    123456 250

    123456 123

  • NineIron (2/12/2013)


    Here's an example list. I need to exclude this MRN from my query because it contains the value 250.

    MRN ICD9Code

    123456 245

    123456 432

    123456 250

    123456 123

    the explanation may be overly simplified, but wouldn't a simple WHERE statement do what you are asking?

    SELECT *

    FROM YOURLIST

    WHERE ICD9Code <> 250

    or do you mean something like this:

    SELECT *

    FROM YOURLIST

    WHERE MRN NOT IN(SELECT MRN FROM YOURLIST

    WHERE ICD9Code = 250)

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • The second one, yes.

    Thanx.

  • Lowell (2/12/2013)


    NineIron (2/12/2013)


    Here's an example list. I need to exclude this MRN from my query because it contains the value 250.

    MRN ICD9Code

    123456 245

    123456 432

    123456 250

    123456 123

    the explanation may be overly simplified, but wouldn't a simple WHERE statement do what you are asking?

    SELECT *

    FROM YOURLIST

    WHERE ICD9Code <> 250

    or do you mean something like this:

    SELECT *

    FROM YOURLIST

    WHERE MRN NOT IN(SELECT MRN FROM YOURLIST

    WHERE ICD9Code = 250)

    Or perhaps this:

    SELECT

    *

    FROM

    YOURLIST yl1

    WHERE

    NOT EXISTS(SELECT 1 FROM YOURLIST yl2 WHERE yl2.ICD9Code = 250 and yl2.MRN = yl1.MRN)

  • Lynn Pettis (2/12/2013)


    Lowell (2/12/2013)


    NineIron (2/12/2013)


    Here's an example list. I need to exclude this MRN from my query because it contains the value 250.

    MRN ICD9Code

    123456 245

    123456 432

    123456 250

    123456 123

    the explanation may be overly simplified, but wouldn't a simple WHERE statement do what you are asking?

    SELECT *

    FROM YOURLIST

    WHERE ICD9Code <> 250

    or do you mean something like this:

    SELECT *

    FROM YOURLIST

    WHERE MRN NOT IN(SELECT MRN FROM YOURLIST

    WHERE ICD9Code = 250)

    Or perhaps this:

    SELECT

    *

    FROM

    YOURLIST yl1

    WHERE

    NOT EXISTS(SELECT 1 FROM YOURLIST yl2 WHERE yl2.ICD9Code = 250 and yl2.MRN = yl1.MRN)

    Or even this

    SELECT *

    FROM YOURLIST Y

    LEFT JOIN YOURLIST as YL on YL.ICD9Code = 250

    WHERE YL.ICD9Code IS NULL

  • Thanx for your input.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply