开发者

problem in using CONCAT if the value is Null in mysql

开发者 https://www.devze.com 2023-01-11 15:29 出处:网络
i used CONCAT to get my tags and topicsbut ifthe story has no tag or topic then result is empty WHERE

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

精彩评论

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