2

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

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.