Ilove Bios
Ilove Bios

Reputation: 3

SQL Query 'NOT IN'

I need to create SQL Query:

List all customers who do not live in Illinois (IL), New York (NY), or California (CA). Sort them by Postal Code in an ascending order. In the result table, show customer name, state, and postal code.

My Query is

SELECT CUSTOMER_NAME, STATE, POSTAL_CODE
FROM CUSTOMER_T
WHERE STATE NOT IN ('CA', 'FL', 'NJ')
GROUP BY POSTAL_CODE

But it doesn't work.

Upvotes: 0

Views: 181

Answers (2)

KS Tech
KS Tech

Reputation: 194

Try this:

SELECT CUSTOMER_NAME, STATE, POSTAL_CODE 
FROM CUSTOMER_T 
WHERE STATE NOT IN ('CA', 'FL', 'NJ') 
Order BY POSTAL_CODE Asc

You don't need Group By Here. Replace Group By With Order By.

Upvotes: 1

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11599

I think you are doing mistake

SELECT CUSTOMER_NAME, STATE, POSTAL_CODE 
FROM CUSTOMER_T 
WHERE STATE NOT IN ('CA', 'IL', 'NY') 
                           ^     ^
Order BY POSTAL_CODE Asc
^

Upvotes: 0

Related Questions