w3resource
SQL exercises

SQL: Using where clause with not operator and NULL

SQL Wildcard & Special Operator : Exercise-21 with Solution

Write a SQL statement to find that customer with all information who gets a grade except NULL value.

Sample table: customer


Sample Solution :

SELECT *
FROM customer
WHERE grade IS NOT NULL;

or equivalent:

SELECT *
FROM customer
WHERE NOT grade IS NULL;

Output of the Query:

customer_id	cust_name	city		grade	salesman_id
3002		Nick Rimando	New York	100	5001
3007		Brad Davis	New York	200	5001
3005		Graham Zusi	California	200	5002
3008		Julian Green	London		300	5002
3004		Fabian Johnson	Paris		300	5006
3009		Geoff Cameron	Berlin		100	5003
3003		Jozy Altidor	Moscow		200	5007

Explanation :

Syntax of using where clause with not operator and NULL

Pictorial presentation :

Exercise: Using where clause with not operator and NULL

Query Visualization for Sample Solution:

Duration:

Query visualization of Using where clause with not operator and NULL - Duration

Rows:

Query visualization of Using where clause with not operator and NULL - Rows

Cost:

Query visualization of Using where clause with not operator and NULL - Cost

Query Visualization for alternate Sample Solution:

Duration:

Query visualization of Using where clause with not operator and NULL - Duration

Rows:

Query visualization of Using where clause with not operator and NULL - Rows

Cost:

Query visualization of Using where clause with not operator and NULL - Cost

 

Practice Online


Contribute your code and comments through Disqus.

Previous: Write a SQL statement to find that customer with all information who does not get any grade except NULL.
Next: Write a query in SQL to display all the data of employees whose last name begins with an 'D'.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming