Relational operators (is null) in SQL

To retrieve the records that contain the value "null" in some field, we cannot use the relational operators seen above: = (equal) and <> (different); we must use the operators "is null" (it is equal to null) and "is not null" (it is not null).


With the following sentence we recover the books that contain null value in the "publisher" field:


 select * from books

  where editorial is null;


Remember that null values ​​are not displayed, the field appears empty.

The following statements will have a different output:


 select * from books where publisher is null;

 select * from books where publisher = '';


With the first sentence we will see the books whose publisher stores the value "null" (unknown); with the second, the books whose publisher keeps a string of 3 blank spaces.


To get the records that do not contain "null", you can use "is not null", this will show the records with known values.


To see the books that do NOT have a "null" value in the "price" field, we type:


 select * from books where price is not null;

Comments

Popular posts from this blog

Data Consistency and Inconsistency - What is Difference

Cardinality in DBMS – max/minimum cardinality & examples

Relational Model in DBMS