Equivalent of "IsNull()" in MySQL?

sivapalani
sivapalani used Ask the Experts™
on

Hi,

Can anyone please tell me the equivalent syntax in MySql for the following?
 
*** isnull(col_name,' ') *** (Microsoft SQL Server)

Since the query,
*** select isnull(col_name,' '), id  from table_name order by id *** gives the following error message

ERROR 1064: You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '' '), id  from qb_stat_table order by id' at line 1


Thanks,
SivaP.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
in MySQL, isnull returns a numerical value telling you if the value is null or not:
http://www.mysql.com/doc/en/Comparison_Operators.html

On that page you can also see the correct function to use, which does also exist in MsSQL:

select coalesce(col_name, ' ') from table_name ...

CHeers
If you are looking for all the records in the table where
the col_name field is null, try this:

SELECT col_name, id FROM table_name WHERE col_name IS NULL order by id

VGR

Commented:
right.
Also possible : if col_name = NULL

your problem is that isnull() doesn't take two columns references as arguments, but only one.

so you could write :
select coalescent(col_name,' '), id  from table_name WHERE col_name is NULL order by id; // here you lack ASC or DESC

Author

Commented:
Thanks to All.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial