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 3219174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:36:52+00:00 2026-05-17T15:36:52+00:00

Suppose I have two tables, one with blog posts and another with readers and

  • 0

Suppose I have two tables, one with blog posts and another with readers and their comments:

Table 1:

table name: BlogPosts:

structure:

id (int)

title (string)

Table 2:

table name: Readers:

id (int)

blog_post_id (int)
name (string)
comment (string)

in the Readers table there is a unique composite key on blog_post_id/name (i.e. one comment per reader per post), though this may not matter for my question.

I want to be able to do a single query tells me what a particular reader’s comment was on each BlogPost, but it should include BlogPosts for which there is no comment entered for that reader (so the query should return one row for each blog post in the database).

I tried several variations that look like this:

SELECT  
     BlogPosts.id,
     BlogPosts.title,
     Readers.name,
     Readers.comment
    FROM
         BlogPosts
    RIGHT JOIN Readers ON
    (BlogPosts.id = Readers.blog_post_id)
    WHERE Readers.name = "joe"

..this just returns the rows where there is actually a comment from joe. Other variations where I was able to get all of the blog posts gave me an invalid identifier whenever I included the where clause.

I am using Oracle Express 10g in case that makes any difference.

Thanks for any help.

  • 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-17T15:36:52+00:00Added an answer on May 17, 2026 at 3:36 pm

    Everything looks correct except that you want to move the WHERE clause into the join, like this:

        SELECT BlogPosts.id,
               BlogPosts.title,
               Readers.name,
               Readers.comment
          FROM BlogPosts
    RIGHT JOIN Readers ON BlogPosts.id = Readers.blog_post_id
           AND Readers.name = 'joe'
    

    You effectively make the OUTER JOIN into an INNER one when you put the Readers.name = 'joe' in the WHERE clause.

    Edit:
    Thanks to the OP for clarification in the comments.
    What you describe in your most recent comment can be achieved simply by switching from a RIGHT JOIN to a LEFT JOIN (as suggested earlier on by another commenter).
    Note that you can get more than one row per BlogPost when there are multiple comments per post.

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

Sidebar

Related Questions

Suppose I have a table whose function is specifically to link two other tables
Suppose I have two tables that are linked (one has a foreign key to
Suppose I have two tables A and B and each one has only 1
Suppose I have two tables 1st table emp EmpID | EmpName|xyz...coloums 1. | Hrishi
In SQL server 2008: Suppose I have two tables. Table1 has 3 fields: Name,
Suppose i have two tables declare @emp table ( EmpID int, EmpName varchar(10) )
Suppose I have a dataset with those two immortal tables: Employee & Order Emp
Suppose I have a database table with two fields, foo and bar. Neither of
Suppose I have a tags table with two columns: tagid and contentid . Each
Suppose I have two branches of a project IMClient-MacOS and IMClient-Windows, and their code

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.