JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

MySQL check if column is empty

Author:JIYIK Last Updated:2025/04/23 Views:

In MySQL or any programming language, there are privileges to add constraints or checks in the instance of creating a table. These constraints help the user to restrict the values ​​inserted into specific fields of the table.

The restriction allows the user to enter a well-defined set of data in the column. However, if these constraints are not applied at schema creation time, you can choose to extract rows by applying a query.


Check if a column is Null or Empty in MySQL

The steps to filter out null or empty column values ​​present in the table are given in the previous section.

The syntax for NULL or Empty check is:

Select expression [, expression2] ...
     FROM table-name
    [WHERE column-name IS NULL or column-name = '']

In the above query, the basic syntax of Select is used to form a statement to extract null and empty values ​​from the table. Specifically, some keywords like IS NULL are used with the column name to filter out the null values.

Whereas for null check, simple match of column name with blank characters is checked. This combination of IS NULL keyword in Select query extracts subset rows that have null or empty value in column name.

Let's look at the IS NULL check in detail:

IS NULL keyword is an operator which is used to check the null value of a column. It is an intermediate operator which is used with other queries to perform operations like select, update, and delete in MySQL.

List of queries before actually checking the query on the table:

  1. Create a table using the create query in MySQL. The query will create the initial schema.
    Create table student ( id varchar(255), name varchar(255), dob date);
    
    In the above query, no constraints such as primary key, uniqueness, or not null are used. Therefore, the pattern extracts the desired results.

    Adding a screenshot of the created table for reference.

    Table schema without constraints

  2. Insert some values ​​into the table.
    Insert into student values ( null,'Josheph', '2022-06-08');
    Insert into student values ( '117','', '2022-06-06');
    
    The above query inserts some required values ​​into the table. Other values ​​can be added as well.

    Below are screenshots for reference.

    List of entries in the table

  3. Rows actual query to filter empty and null rows.

    Query and execute MySQL statements:

    Select * from student where name IS NULL or name = '';
    Select * from student where id IS NULL or id = '';
    
    The above query extracts the list of values ​​from the above table whose names are null or empty. Similarly, in the second Select query, the check on the ID field property matches the empty character value or the null value.

    Below is a screenshot of the actual local operation for reference.

    Local running screenshots:

    MySQL check if column value is empty

    MySQL select column value is empty

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Display tables and database structure in MySQL

Publish Date:2025/04/23 Views:97 Category:MySQL

Today, we will learn about queries in MySQL that can display the table and database structure. We will use the mysqldump utility, DESCRIBE the , SHOW TABLES and SHOW CREATE TABLE the statements. We are using MySQL version 8.0.28 while writi

Select first row from MySQL table

Publish Date:2025/04/23 Views:112 Category:MySQL

Today, we will explore three scenarios and their solutions where we want to select the first row from a MySQL table. In the first scenario, we will learn to get the first row from a MySQL table where there are multiple instances of a partic

Insert timestamp into MySQL table

Publish Date:2025/04/23 Views:77 Category:MySQL

Today, we will learn how to TIMESTAMP insert date and time into a type column of a MySQL table according to the table definition. Create a MySQL table First, we will create the tables that we will use in this tutorial. Sample code: CREATE T

The difference between two tables in MySQL

Publish Date:2025/04/23 Views:102 Category:MySQL

In this article, we will learn how to find the difference between two tables in MySQL. The difference between two tables in MySQL We often need to compare two tables to find records in one table that have no matching records in the other ta

MySQL sorts data alphabetically

Publish Date:2025/04/23 Views:129 Category:MySQL

In this article, we will learn about various ways to sort data alphabetically in MySQL. Sort MySQL data alphabetically When you use the SELECT command to query data from a table, the rows in the result set are in arbitrary order. To order t

Display the current database in MySQL

Publish Date:2025/04/23 Views:199 Category:MySQL

This article focuses on the various queries that can be used to display the current database in MySQL. We will learn by using the Windows command line and MySQL Workbench. Display the current database in MySQL We can use the following query

Check if a database exists in MySQL

Publish Date:2025/04/23 Views:179 Category:MySQL

In this article, we will introduce many ways to check if a database exists in MySQL. Check if the database exists in MySQL The system schema is the schema that MySQL uses. It includes tables that contain data needed by a running MySQL serve

Get the sum of multiple columns in MySQL

Publish Date:2025/04/23 Views:125 Category:MySQL

In this article, we will learn how to sum multiple columns in MySQL. Sum multiple columns in MySQL You can use aggregate functions SUM() to calculate the total value in a collection. SUM() The function calculation does not consider NULL val

MySQL ForEach Loop

Publish Date:2025/04/23 Views:164 Category:MySQL

This article describes how to simulate a foreach loop in MySQL using INSERT, SELECT, WHERE, and JOIN in one statement. MySQL foreach loop To understand foreach loop simulation, let us create three tables with the following names and attribu

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial