Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL IFNULL on SELECT * statement

Tags:

sql

mysql

ifnull

Is there a way to set a default value for all returned values that are null, specifically in MySql?

Instead of

SELECT 
  IFNULL(foo, 0),
  IFNULL(bar, 0),
  IFNULL(baz, 0)
FROM table

I would like to do something like:

SELECT IFNULL(*, 0)
FROM table

// this does not work, but I'm looking for something like it
like image 920
sabrams Avatar asked Oct 18 '22 07:10

sabrams


1 Answers

A result of a function in SQL is a single value (column), not a list of columns. So there isn't, and can't be, such a construct. You'd have to handle every column individually, unfortunately.

like image 167
Mureinik Avatar answered Oct 21 '22 03:10

Mureinik