How to change null field to not return anything?

Asked

Viewed 852 times

3

In a query has many fields not being filled in, would like to exchange the null that is being printed so that nothing appears in the print.

  • Welcome to Sopt. Post your query so we can help.

1 answer

8


Use the function COALESCE:

COALESCE(coluna, '')

The result of this function is the first of the two arguments that is not null, so if the first is not, it takes the value of the column, otherwise it takes the string empty. This can be used anywhere in the query.

Example:

SELECT nome, COALESCE(endereco, '') AS endereco FROM tabela

I put in the Github for future reference.

  • IFNULL of the same correct result?

  • 2

    @Viniciosyals in Mysql yes.

  • Yes, in Postgresql also works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.