Steve Tinsley
asked on
MySQL Query - Return 0 rather than NULL
I have a mysql query that returns the next number:
The problem is if all the numbers are NULL it returns NULL... How can I set it so that if all are NULL it returns 0 (+1)
?
SELECT dispOrder+1 FROM (SELECT MAX(dispOrder) AS dispOrder FROM question) AS x
The problem is if all the numbers are NULL it returns NULL... How can I set it so that if all are NULL it returns 0 (+1)
?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Probably better to use an auto_increment column:
https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html
You can have gaps with an auto_increment column but using your approach, you can have collisions.
Ifnull(column,1)
I find it difficult to answer a question or suggest an approach when a question has an approach that does not match the asker's need as a basis.
You have a select from a select.
Max(ifnull(column,1)) might be a way to limit nulls ......
As part of your query.