Mysql – select only the field that has only the data

MySQL

create table test (txt1 int(3) not null,txt2 int(3) not null, txt3 int(3) not null)

Now if I insert a record in this table like.

insert into test ('txt1','txt2','txt3') values(25,null,null),(78,null,null)

From the above queries table is created and inserted with couple of records. Can any one kindly give me solution how to create query to display the field only that contains records. If the field contain null values the its should not display.

Best Answer

If you intend to run a query whose result does not display the word "NULL" for a missing number value, but displays white space, then in MySQL you may use this formula:

IFNULL(FORMAT(txt2, 3, 0), '')

FORMAT converts the number to a string of 3 digits. However, if the number is NULL then the result is a NULL string. Then the formula IFNULL() returns its first term unless that is NULL, in which case the second term appears instead.