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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:12:55+00:00 2026-06-18T14:12:55+00:00

I need to know what is the best practice for storing the following data:

  • 0

I need to know what is the best practice for storing the following data:

Lets say I have multiple garages, each garage holds different types of vehicles with totally different attributes (e.g. planes, tanks, ships, bikes). I need to query all the vehicles in one garage, including their attributes.

What would be a good practice to store and query this data with one universal query? Store all vehicles in one table, with every possible attribute?
Or create multiple tables, each for a specific type of vehicle? Then, how do I query all the different vehicles of one garage, without knowing which type they are?

Is something like this even possible with a single query? Or do I have to create multiple queries to get the data?

I hope you understand what I am trying to achieve.

  • 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-18T14:12:57+00:00Added an answer on June 18, 2026 at 2:12 pm

    This sure is possible, however it involves some planning when creating your datamodel.

    There are, as you already mentioned, different ways to implement sub-type-super-type relations (aka Inheritance).

    1.) All in one Table

    In this case I would model your problem somewhat like this:

    Garage(GarageId_PK, Name)
    Vehicle(VehicleId_PK, LicenceNr, GarageId_FK, SomethingOnlyCarsHave, SoemthingOnlyMortorbikesHave, Type)
    

    For the Type you could give IDs and have a separate table where you relate the IDs to Names or simply write the names there (not a very clean solution!).
    Btw.: If you want to have multiple inheritance (which I guess you don’t need for vehicles) you could also make Type a bitmask.

    Personally I don’t really like this approach, but it is quite ok to do this. Oracle i.e. suggests this in their study material. Also it’s the simpler solution for your one query problem:

    SELECT *
    FROM Vehicle v
    INNER JOIN Type t ON (v.Type = t.TypeId)
    WHERE GarageId = 42
    

    2.) Table for each Subtype

    To me, this feels like the cleaner solution, because you have less NULL values, but you need a bit more work to get everything in one query.

    Garage(GarageId_PK, Name)
    Vehicle(VehicleId_PK, LicenceNr, GarageId_FK)
    Car(VechicleId_PK_FK, SomethingOnlyCarsHave)
    Motorbike(VechicleId_PK_FK SoemthingOnlyMortorbikesHave)
    

    This theoretically allows for multiple inheritance and you should write a trigger allowing only subtype.

    SQL in this case:

    SELECT *
    FROM Vehicles v
         LEFT JOIN Car c ON(v.VehicleId = c.VehicleId)
         LEFT JOIN Motorbike m ON (v.VehicleId = m.VehicleId)
    WHERE GarageId = 42
    

    Or if you have more types you could put the ugly stuff into a View:

    CREATE OR REPLACE View v_allVehicles AS
    (SELECT *
     FROM Vehicles v
          LEFT JOIN Car c ON(v.VehicleId = c.VehicleId)
          LEFT JOIN Motorbike m ON (v.VehicleId = m.VehicleId)
    
    SELECT *
    FROM v_allVehicles
    

    EDIT:

    A word on notation: When I put _PK behind a name it referes to the column being a primary key. _FK to a foreign key.

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

Sidebar

Related Questions

I need to know what is the best practice for sending emails from my
for a data warehouse project I need to know about some best practices regarding
Lets say I'm storing an array or object called $_SESSION[logged_in_user] . If I need
I want to know what's the best practice for the following case : I'm
I know that it doesn't look like best practice but I need to generate
I need to know which of the 3 is best for me. My requirements
I'm new to Django and I want to know the best practice for resolving
I would like to know what is the best practice in designing the constructors
I need an advice on best practices for DRYing view code. I have three
I have a situation where I need to store a general piece of data

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.