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

  • Home
  • SEARCH
  • 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 8627223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:13:22+00:00 2026-06-12T08:13:22+00:00

I have a conceptual question that I’m hoping someone more versed in sql database

  • 0

I have a conceptual question that I’m hoping someone more versed in sql database design can help me with. I have a table in which each row has a corresponding row in one of several other tables. Ie. rows in table 1 have a corresponding row in either table 2, table 3 or table 4 (but NEVER in more than 1… the corresponding row can only be in one of the other tables).

What is the best way to set this structure up. If I put an othertable_id column and a tablename column in table 1, I can guarantee that there is only 1 corresponding row in the other tables, but it seems like a really inflexible messy solution. On the other hand if I put just a table1_id column in table2, table3, and table4, it seems like I will need to run 3 different queries each time I want to find the row that corresponds to a row in table1, AND it seems like I cannot guarantee there only being one entry in any of the three tables for my row in table1.

Does anyone have any suggestions?

  • 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-12T08:13:24+00:00Added an answer on June 12, 2026 at 8:13 am

    I would use the second solution, and use a trigger to ensure no more than one related row exists.

    The query would look like:

    select *
    from table1 t1
    left outer join table2 t2 on t1.id = t2.table1_id
    left outer join table3 t3 on t1.id = t3.table1_id
    left outer join table4 t4 on t1.id = t4.table1_id
    

    If there was a common column among the tables you wanted, e.g., value, you could get it like this:

    select t1.*,
        coalesce(t2.value, t3.value, t4.value) as value
    from table1 t1
    left outer join table2 t2 on t1.id = t2.table1_id
    left outer join table3 t3 on t1.id = t3.table1_id
    left outer join table4 t4 on t1.id = t4.table1_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

More of a design/conceptual question. At work the decision was made to have our
I'm new to programming and I have a conceptual question. That is, can exception
I have a more conceptual question in Rails... or Ruby for that matter: Is
this is more a conceptual question. Consider you have a php framework that runs
This is more of a conceptual question than anything. I have a base class
I have an interesting situation here this time. This more of a conceptual question,
This is more of a conceptual question than an actual implementation and am hoping
This is more a conceptual question. It's inspired from using some extremely large table
I have this conceptual question about ajax that I'm not sure if I understand.
This is more of a conceptual integrity question for something that's been bothering me.

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.