I have a reputation points table for my members.
rep_id | mem_id | activity | points | article_id | comment_id
---------|------------|-------------------|------------|----------------|-----------------
1 | 99 | Posted Comment | 5 | 10343 | 239403
2 | 99 | Introduction | 50 | |
3 | 99 | Liked Comment | 5 | 748 | 9302
As you can see, not all reputation points have an article_id or a comment_id, but when I list these records, if the record does have an article_id, I need to grab the article_title from the blog_articles table. The same with comment_id, if it’s present, I need to grab the comment from the blog_comments table. If article_id or comment_id is missing, just print the original record as-is.
I would really appreciate if somebody could tell me which join to use for this query. I THINK, by looking at the documentation, it’s a LEFT JOIN I need, which prints all records from the left, even though there are no matches in the right – but really unsure.
I’m not looking for any code, just tell me which join is recommended and I will code it.
Left join is what you need, indeed. If the record does not have an
article_idthe value forarticle_titlewill beNULL. The same applies tocomment_id/comment.