How to check if a column is empty or null in MySQL - MySQL Developer Tutorial

How to check if a column is empty or null in MySQL 

Let's say you have table with some column which has Null values and also blank values '',' ','    ' etc. You need to check if the column contain Null values or blank values, we can understand by using below example.

Let's create customer table and then insert some Null values in last name and blank values ('','    ') and then use select query to get Null values and blank values.


CREATE TABLE `customer` (
  `idcustomer` int(11) NOT NULL auto_increment,
  `firstname` varchar(50)  NULL,
  `lastname` varchar(30)  NULL,
  `age` int(11) DEFAULT NULL,
  `phonenumber` char(11) DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `gender` char(1) NOT NULL,
  Constraint pk_idcustomer Primary key (idcustomer)
) ;



Insert some values in customer table.


insert into customer
(firstname,lastname,age,phonenumber,dob,gender)
values
('Aamir1',null,39,'505-414000','1980-01-01','M'),
('Aamir2','',40,'505-4141000','1980-02-01','M'),
('Aamir3',' ',41,'505-4141000','1980-02-01','M');


Check the column if have null and empty values by using below query

Select * from customer 
where lastname is null or rtrim(ltrim(lastname))='';

2 comments:

  1. If you have been looking for a perfect platform to enjoy high quality sex video chats for a long time, then I recommend you Bongacams ! The video chats work flawlessly, and the models are always ready to fulfill your wildest fantasies. The interface of the site is very user-friendly and intuitive, which makes finding the right chat rooms quick and easy. Especially pleasing is the possibility of private chats, where you can get a personalized experience. I recommend everyone to try BongaCams, you definitely won't regret it!

    ReplyDelete