开发者

problem in using CONCAT if the value is Null in mysql

i used CONCAT to get my tags and topics but if the story has no tag or topic then result is empty

 WHERE 

    CONCAT( ' ', table_stories.ta开发者_开发问答gs, ' ' )
    LIKE CONCAT( '%', table_tags.tid, '%' ) 

    AND

    CONCAT( ' ', table_stories.associated, ' ' )
    LIKE CONCAT( '%', table_topics.topicid, '%' ) 

as you see , everything fine unless we have story that has no tag or associated

i used

  table_stories.tags IS NULL OR

but problem still exists and cant fetch stories with no tag or associated

how can i fix this


I don't have mysql handy to test but COALESCE() is probably the function you are looking for.

This returns the first non-null argument (See Documentation)

So

CONCAT(' ' , COALESCE(table_stories.associated, ' '), ' ')

should do the job

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜