MySQL Where IS NOT NULL Examples

MySQL where not null query; Through this tutorial, i am going to show you how to use MySQL WHERE IS NOT NULL with help of examples.

MySQL Where IS NOT NULL Query With Examples

  • Syntax of MySQL Where IS NOT NULL
  • Parameters of MySQL Where IS NOT NULL
  • Example 1 :-Using SELECT Clause With MySQL IS NOT NULL
  • Example 2 :-Using “INSERT INTO” Clause With MySQL IS NOT NULL
  • Example 3 :-UPDATE Clause With MySQL IS NOT NULL
  • Example 4 :-DELETE Clause With MySQL IS NOT NULL
  • Example 5 : Using IS NOT NULL On Join Conditions
  • Example 6 :-Using IS NOT NULL With Logical Operator

In order to manipulate data in MySQL database tables, we can use “IS NOT NULL” with MySQL clauses with examples. MySQL clauses like INSERT INTO, SELECT, UPDATE, DELETE etc. And Also we can use this with logical operator like (AND, OR) etc.

Syntax of MySQL Where IS NOT NULL

MySQL syntax is “IS NOT NULL” given below : –

table_column_name IS NOT NULL
OR
exp IS NOT NULL

Parameters of MySQL Where IS NOT NULL

table_column_name(exp) :- It’s the table column name that you check the value if it is not NULL.

When we use MySQL “IS NOT NULL” with any table column, then it will be true and false.

  • If the given condition is fulfilled, then it will come true.
  • If the given condition is not fulfilled, then it will come false.

Example 1 : Using SELECT Clause With MySQL IS NOT NULL

See the following example of mysql is not null with select clause; as follows:

 SELECT *
FROM users
WHERE email_address IS NOT NULL;

The above example query will fetch all records from database table users using MySQL IS NOT NULL & SELECT Clause. Where the email_address column does not contain a null value.

Example 2: Using “INSERT INTO” Clause MySQL “IS NOT NULL”

See the following example of mysql is not null with insert into clause; as follows:

 INSERT INTO vendors (
name,
phone,
addressLine1,
addressLine2,
city,
state,
postalCode,
country,
customer_id
)
SELECT
name,
phone,
addressLine1,
addressLine2,
city,
state ,
postalCode,
country,
customer_id
FROM
customers
WHERE
country IS NOT NULL;

For the above example of MySQL “IS NOT NULL” with “INSERT INTO” Clause will insert all records from database table vendors. Where the country column does not contain a null value.

Example 3: UPDATE Clause With MySQL “IS NOT NULL”

See the following example of mysql is not null with update clause; as follows:

 UPDATE users
SET verified = 1
WHERE status IS NOT NULL;

It above example query will update all records from database table users using MySQL IS NOT NULL & UPDATE Clause. Where the “status” column does not contain a null value.

Example 4: DELETE Clause With MySQL “IS NOT NULL”

See the following example of mysql is not null with delete clause; as follows:

 DELETE FROM users
WHERE verified IS NOT NULL;

The above query will delete all records from database table users using MySQL IS NOT NULL & DELETE Clause. Where the “verified” column does not contain a null value.

Example 5 : Using IS NOT NULL On Join Conditions

See the following example of mysql is not null with join clause; as follows:

 SELECT * FROM users 
LEFT JOIN posts ON post.user_id = users.id
WHERE user_id IS NOT NULL;

It will fetch records from database table users using MySQL IS NOT NULL & LEFT JOIN Clause. Where the “user_id” column does not contain a null value.

Example 6 : Using IS NOT NULL With AND Logical Operator

See the following example of mysql is not null with logical and operators; as follows:

 SELECT * FROM users 
WHERE email_address IS NOT NULL
AND mobile_number IS NOT NULL;

The above MySQL query get all the records from database table users using MySQL IS NOT NULL & AND logical operator. Where the “email_address” and “mobile_number” column does not contain a null value.

See the following example of mysql is not null with logical or operators; as follows:

 SELECT * FROM users 
 WHERE email_address IS NOT NULL 
 OR mobile_number IS NOT NULL;

Where “both email address” and “mobile number” The value of one of the columns is also found. than the above query fetch all records from database table users by using IS NOT NULL with OR logical operator.

Conclusion

In this mysql tutorial point – we have learned how to use “IS NOT NULL” with MySQL basic clauses, join clause & logical operators with examples.

Leave a Comment