mysql SELECT column only if exists -


i have 5 tables want select data from, 5th table (named comment) empty. when happens want query return null values table, , return other values (the 5th table includes user comments, there none).

here query:

select articles.title, articles.posted, articles.body, authors.name, authors.img, authors.bio, comment.user_id, comment.text, comment.article_id, group_concat(categories.cat_name) cat_name articles, authors, categories, article_categories, comment  articles.author_id = authors.id , articles.id = article_categories.article_id , article_categories.category_id = categories.id , articles.id = comment.article_id , title :title; 

the :title comes pdo , not relevant here.

the problem comes and articles.id = comment.article_id. don't know how write in way check this, if it's there , ignore otherwise.

thanks help

you should use proper join syntax, , in case instead of inner join use left join comment table:

select articles.title, articles.posted, articles.body, authors.name, authors.img, authors.bio, comment.user_id, comment.text, comment.article_id, group_concat(categories.cat_name) cat_name articles inner join authors on articles.author_id = authors.id inner join article_categories on articles.id = article_categories.article_id inner join categories on article_categories.category_id = categories.id left join comment on articles.id = comment.article_id title :title; 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -