views:

82

answers:

4

How can I see what is not in the table... I know I know...can only see what is there but come on!!!

So!!

select * from ORDER where State IN ('MA','PA','GA','NC')       

So I will get MA and PA but I want to see GA and NC....

NOT IN will return NY,NJ,CT ect.... I just want to see what is in the ( )

+2  A: 

It looks like you are missing a single quote ' in front of GA.

JNK
A: 

Are you just trying to find out which states there are except for those four? If so:

SELECT DISTINCT State FROM dbo.ORDER WHERE State NOT IN ('MA', 'PA', 'GA', 'NC')
Andrew
I don't think that's the question.
NullUserException
@NullUserException - It's exceptionally hard to tell, though!
JNK
+1  A: 

My understanding of the question is: For a given list of states, which ones do not exist in the Order table?

This will show you what states out of the four listed below have no corresponding records in the Order table:

select distinct s.State
from
(
    select 'MA' as State
    union all
    select 'PA'
    union all
    select 'GA'
    union all
    select 'NC'
) s
left outer join [Order] o on s.State = o.State
where o.State is null
RedFilter
+1 - This is a great guess at what OP is after.
JNK
I Agree... This is probably the best, though I would ditch the Distinct and use group by, personal preference.
Nicholas Mayne
+1  A: 

I'm going to try to read between the lines a little here:

;with cteStates as (
    select 'MA' as state
    union all
    select 'PA'
    union all 
    select 'GA'
    union all
    select 'NC'
)
select s.state, count(o.state) as OrderCount
    from cteStates s
        left join [order] o
            on s.state = o.state
    group by s.state
Joe Stefanelli