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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:40:36+00:00 2026-06-10T00:40:36+00:00

I have three tables AA, BB and CC. BB and CC has one to

  • 0

I have three tables AA, BB and CC. BB and CC has one to one mapping to table AA ( with foreign key column : aa_id in both tables). Provided one condition that only either BB or CC can have reference to a row of table AA.

I would like to select latest 1000 rows from AA either joining with BB or CC.
I could do separate queries to select 500 rows joining with BB and CC separately and make 1000. But this will not guarantee that I am getting latest 1000 rows from AA table.

So, I came up with following query to select record from AA by joining with BB and CC at same time. But due to my restriction ( only either BB or CC can have reference to a row of table AA), I am getting 0 rows from query below.

SELECT  * FROM AA 
       INNER JOIN BB  ON (
            AA.id = BB.aa_id
            AND SOME_CONDITION
        ) 
        INNER JOIN CC  ON (
            AA.id = CC.aa_id
            AND SOME_CONDITION
        )
ORDER BY
AA.id DESC limit 1000;

Could you please tell me how to do this? Is there any way so that I can OR these two JOIN conditions?

  • 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-06-10T00:40:38+00:00Added an answer on June 10, 2026 at 12:40 am

    just change your INNER JOINs to LEFT OUTER JOINs and you’ll be fine. you may want to read this article on codinghorror.com for an explanation of different join-types.

    your result should look like this:

    SELECT * FROM AA 
      LEFT OUTER JOIN BB  ON (
        AA.id = BB.aa_id
        AND /* SOME_CONDITION */
      ) 
      LEFT OUTER JOIN CC  ON (
        AA.id = CC.aa_id
        AND /* SOME_CONDITION */
      )
    ORDER BY AA.id DESC
    LIMIT 1000;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table column where each row has one of three states, and
I have three tables: User, Employee and Worker. User table has one-to-zero-or-one relationship with
I have a table that has three different date columns, so I set each
I have a SqlServer 2008 table which has a Primary Key (IsIdentity=Yes) and three
I have a table in my data base that has three columns: Screen, Icon,
I have this schema: There is a table for persons. Each person has one
I have a table in HTML which has three columns i.e Error - User
I have a table PGM_MASTER, which has three columns PGM_ID | int(11) PGM_ENV_ID |
I have a product table that has a many-to-many relation to itself (using a
I have two classes. One is called Employee and the other EmployeeDetails that has

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.