tags:

views:

29

answers:

1

hey guys

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.tags, ' ' )
    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

+2  A: 

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

Steve Weet
@Mac. I didn't post full code as I do not have access to mysql to test it. But within your CONCAT methods wrap any columns that could be null with a call to COALESCE(column, ' '). This will ensure that if the value is null you get a space instead.
Steve Weet