'I need to delete all the records whise expiry date has not been given I wrote the following

I need to delete all the records whose expiry date has not been given. I wrote the following command, which has not deleted the records.

delete * from products where expdate=null;

Help to run the query by removing the error



Solution 1:[1]

Today we need to eliminate a lot of data with null data, which is the beginning.

DELETE FROM products WHERE expdate = NULL;

Found incorrect, the number of affected rows is 0;

Should be written as follows :

delete from products where expdate IS NULL;

As you were told in the comments.

Null as a value

In simple terms, NULL is simply a placeholder for data that does not exist. When performing insert operations on tables, there will be times when some field values will not be available.

To meet the requirements of true relational database management systems, MySQL uses NULL as the placeholder for values that have not been sent. The following screenshot shows what NULL values look like in the database.

enter image description here

Let us now look at some of the basic concepts for NULL before going deeper into the discussion.

  • NULL is not a data type; this means that it is not recognized as "int", "date" or any other defined data type.

  • Arithmetic operations involving NULL always return NULL, e.g. 69 + NULL = NULL.

  • All added functions affect only rows that do not have NULL values.

IS NULL : is the keyword that performs the Boolean comparison. It returns true if the provided value is NULL and false if the provided value is not NULL.

NOT NULL : is the keyword that performs the Boolean comparison. It returns true if the value provided is NOT NULL and false if the value provided is null.

Let us now look at a practical example that uses the NOT NULL keyword to remove all column values that have null values.

Continuing with the previous example, suppose we need details of members whose contact number is not null. We can run a query like

 SELECT * FROM `members` WHERE contact_number IS NOT NULL;

Executing the above query only provides records where the contact number is not null.

Suppose we want member records where the contact number is null. We can use the following query

SELECT * FROM `members` WHERE contact_number IS NULL;

URL : https://guru99.es/null/

I hope it helps you, greetings.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1