Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect parameter when using IsNull in MySQL

Tags:

join

mysql

I've been trying to use the IsNull() function to ensure that there is a value for a field.

SELECT crawled.id,
       IsNull(sranking.score,0) as Score,
       crawled.url,
       crawled.title,
       crawled.blurb
FROM crawled
    LEFT JOIN sranking ON crawled.id = sranking.sid
WHERE crawled.body LIKE '%".$term."%'
ORDER BY Score DESC LIMIT " . $start . "," . $c

But I get the error message:

Incorrect parameter count in the call to native function 'IsNull'

Anybody have any ideas? I'm pretty new to MySQL.

like image 205
andy Avatar asked Dec 12 '22 22:12

andy


1 Answers

ISNULL tests if the passed expression is NULL. What you need is IFNULL, or COALESCE, as xyld has mentioned.

SELECT crawled.id, IFNULL(sranking.score, 0) as Score, ...
like image 98
newtover Avatar answered Dec 22 '22 22:12

newtover