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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:47:30+00:00 2026-05-26T04:47:30+00:00

What is the best way to setup this table structure. I have 3 tables,

  • 0

What is the best way to setup this table structure.

I have 3 tables, one table we’ll call fruit and the other two tables are properties of that fruit so fruit_detailed and fruit_basic.

fruit

id | isDetailed

fruit_detailed

id | price | color | source | weight | fruitid?

fruit_basic

id | value | fruitid?

So what I want to do is have a property in fruit called isDetailed and if true, fill the fruit_detailed table with properties like color, weight, source, etc (multiple column). If its false then store in fruit_basic table with properties written in a single row.

Storage sounds quite basic but if I want to select a fruit and get its properties, how can I determine which table to join? I could use and IF statement on the isDetailed property and then join like that but then you have two different types of properties coming back

How would you create the tables or do the join to get the properties? Am I missing something?

  • 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-26T04:47:31+00:00Added an answer on May 26, 2026 at 4:47 am

    I would probably model this like so:

    CREATE TABLE Fruits (
        fruit_id    INT    NOT NULL,
        CONSTRAINT PK_Fruit PRIMARY KEY CLUSTERED (fruit_id)
    )
    
    CREATE TABLE Fruit_Details (
        fruit_id    INT               NOT NULL,
        price       MONEY             NOT NULL,
        color       VARCHAR(20)       NOT NULL,
        source      VARCHAR(20)       NOT NULL,
        weight      DECIMAL(10, 4)    NOT NULL,
        CONSTRAINT PK_Fruit_Detail PRIMARY KEY CLUSTERED (fruit_id),
        CONSTRAINT FK_Fruit_Detail_Fruit FOREIGN KEY (fruit_id) REFERENCES Fruit (fruit_id)
    )
    

    I had to guess on appropriate data types for some of the columns. I’m also not sure exactly what the “value” column is in your Fruit_Basic table, so I’ve left that out for now.

    Don’t bother putting a bunch of IDs out there simply for the sake of having an ID column on every table. The Fruits->Fruit_Details relationship is a one-to-zero-or-one relationship. In other words, you can have at most one Fruit_Details row for each Fruits row. In some cases you might have no row in Fruit_Details for a particular row in Fruits.

    When you’re querying you can simply OUTER JOIN from the Fruits table to the Fruit_Details table. If you get back a NULL value for Fruit_Details.fruit_id then you know that the fruit doesn’t have any details. You can always include the Fruit_Details columns, they’ll just be NULL if the row doesn’t exist. That way you can always have homogeneous resultsets. As you’ve discovered, otherwise you end up having to worry about different column lists coming back depending on the row in question, which will lead to tons of headaches.

    If you want to include an “isDetailed” column then you can just use this:

    CASE WHEN Fruit_Details.fruit_id IS NULL THEN 0 ELSE 1 END AS isDetailed
    

    This approach also has an advantage over putting all of the columns in one table because it lowers the number of NULL columns in your database and depending on your data can substantially decrease storage requirements and improve performance.

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

Sidebar

Related Questions

2 part question: 1st What is the best way to setup a table/relationship structure
I have an existing table structure that looks something like this: AnimalTable ------------- |Id
I have an audit table setup which essentially mirrors one of my tables along
What is the best way to setup one Linux box to listen on its
I have a MySql db with innoDB tables. Very simplified this is how two
I have a table for product category that has a hierarchical structure. Each Category_ID
This question is related to this one: Best way to store product colors in
What is the best way to setup your pool with respect to:- When do
What's the most common/best way to setup a WCF service project and applications? Here's
So I do not reinvent the wheel, what is the best way to setup

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.