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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:28:32+00:00 2026-06-15T15:28:32+00:00

I have a 4 types of users and each have specific data, but they

  • 0

I have a 4 types of users and each have specific data, but they also share commun data, like username, password ..

My first thought is to create a main users table with user_type column. Then when querying user data i can just first select their user_type and then depending on the output run a different query to grab “user type” specific data.
I am not fond of this as i wish i could grab all user related data with one query and ideally using Foreign Keys.

Second idea is to not have a user_type column in the users table and instead use foreign key that from a specific user type table will point to a row the main users table.
I like that a bit better though i guess i will have to run N queries, where N is the number of user type every time i need to grab user data.

Are there any other options ? What would be the good practice in such a case ?

Many thanks

  • 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-15T15:28:33+00:00Added an answer on June 15, 2026 at 3:28 pm

    Your case looks like an instance of class/subclass.

    There are two classic ways to design SQL tables to deal with subclasses. Each has advantages and disadvantages.

    One way is called “Single Table Inheritance”. In this design there is just one table for all types of users. If a given column doesn’t pertain to a given row, the intersection is left NULL. A column can be added to indicate the user type.

    Another way is called “Class Table Inheritance”. This is much like the answer Nanego gave, with a few minor changes. There is one table for users, with all the common data, and a id field. There is one table for each subclass, with data that pertains to that subclass. The id field is often set up as a copy of the id field in the matching row back in the users table. This way the subclass key can do double duty, acting as both a primary key and as a foreign key referencing the user table. This last technique is called “Shared Primary Key”. It requires a little programming at insert time, but it’s well worth it. It enforces the one-to one nature of the relationship, and it speeds up the necessary joins.

    You can look up all three of these designs as tags in SO or as articles out on the web.

    single-table-inheritance
    class-table-inheritance
    shared-primary-key

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

Sidebar

Related Questions

I have a table with user items. Each user may have several types of
I have an application where users can store items. Now each type of account
I have two types of users for my system, normal human users with a
I have two types of users on the database: -Web registered users -Twitter users
I have several entities which respresent different types of users who need to be
I have a rails application that has three different types of users and I
I have a thread, and different users rating a movie in 3 different types.
I have two user types in my application: Investors and Advisors , they both
I have a table that contains 4 varying types of data and depending on
I have a table. A large table with 25 columns each containing atomic 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.