MySQL : Concat String return null


SELECT p.*
FROM 2_crm_persons p
WHERE CONCAT(p.name, p.name2) LIKE ‘%blackphp%’

That’s query above give a null result because field name or field name2 is null.

The solution is, check field value with IFNULL and give result empty string if null : IFNULL(p.name,”).

Query will be :

SELECT  p.*
FROM 2_crm_persons p
WHERE CONCAT(IFNULL(p.name,”),IFNULL(p.name2,”)) LIKE ‘%blackphp%’

Regard.

Blackphp

About blackphp

All about programming php, ajax, jquery, mysql, etc, tips n trick. Now, i'm concern in php programming with codeigniter framework n also training my design skill with photoshop or corel... wish me luck! ('o')

Posted on June 19, 2013, in mYsQL, MySQL Theory and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: