MySQL: How to use IFNULL - Incorrect Parameter Count Error Message
Question by Guest | Last update on 2021-05-13 | Created on 2015-07-07
I would like to use the function IFNULL in MySQL in order to check whether a field in my table is NULL.
Up to now, I have tried the following query:
SELECT IFNULL(col, 0, col) FROM tab
This should return the content of "col" whenever "col" is not NULL or 0 if "col" is NULL.
However, I always get an error message stating that I have used a wrong number of parameters when calling the function:
Incorrect parameter count in the call to native function 'IFNULL'
What am I doing wrong? How should I call IFNULL instead? Does someone have any idea?
Related Topics
Lazarus: Program without GUI - Many WSRegister Errors
Question | 6 Answers
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
jQuery: Count characters from multiple input fields
Tip | 0 Comments
MySQL: Check for NULL
Question | 1 Answer
Create Custom Error Pages for Website
Tip | 0 Comments
Reload Images, CSS, JS and Web Pages despite Browser Cache
Tip | 2 Comments
Delphi/Lazarus: 3 Ways to round a Number to X Decimal Places
Tutorial | 7 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
IFNULL expect 2 parameters, however, you are passing 3 parameters.
The first parameter for IFNULL is the value that should be checked. This value is returned if it is not NULL. However, if it is NULL, instead the second parameter will be returned.
So, your query should look like this:
For clarification, here are some more examples for using IFNULL:
IFNULL(1, 0) returns 1 - because the first parameter is not NULL, the first parameter will be returned. IFNULL(NULL, 0) returns 0 - the first parameter is NULL, so the second parameter will be taking into account. IFNULL('', 0) returns '' - because '' is not NULL.
By the way, alternatively, you can also work with IF. You can find an example in the topic "Check for Null".
Last update on 2021-05-13 | Created on 2015-07-08