Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:52:44+00:00 2026-05-27T22:52:44+00:00

I have this comment table where users can post comment as well as guest,

  • 0

I have this comment table where users can post comment as well as guest, i can fetch users comments like this

SELECT `comments`.`user_id`, `comments`.`pubdate`,    `comments`.`comment`,
`comments`.`guest_name`,
`comments`.`id`, 
`users`.`username`, 

FROM (`comments`) 
JOIN `users` ON `comments`.`user_id` = `users`.`user_id` 
WHERE `item_id` = '64' AND `section` = 'blog'

problem is guest users don’t have user id hence thier id goes to db as 0 so it is not displayed, how can i show comments of both users and guest ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:52:45+00:00Added an answer on May 27, 2026 at 10:52 pm

    You should use LEFT JOIN

    SELECT `comments`.`user_id`, `comments`.`pubdate`,    `comments`.`comment`,
            `comments`.`guest_name`,
            `comments`.`id`, 
            `users`.`username`, 
    
    FROM `comments`
    LEFT JOIN `users` ON `comments`.`user_id` = `users`.`user_id` 
    WHERE `item_id` = '64' AND `section` = 'blog'
    

    If there’s no matching user for comments.user_id, then users.username will be NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this mysql table called comments which looks like this: commentID parentID type
I have this part of code: def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(params[:comment])
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I have a bit of php code like this: $test = <!--my comment goes
In a blog in Rails I want to have paths like http://mydomain.com/posts/28383/comments#21 This is
I'm trying to mimic something similar to FB. Basically, users can post comments in
Quick sum up: I have a social website where users can follow/post/vote etc. I
I have a table posts with columns post_id , user_id , post . When
I have three tables: products (product_id, title) comments (comment_id, product_id, user_id, comment, post_date) bookmarks
I have this in one of my haml views: -form_for :news_item_comment, :url=>{:id => comment.id,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.