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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:58+00:00 2026-05-26T21:57:58+00:00

I am a bit indecisive about a certain database table structure, here is the

  • 0

I am a bit indecisive about a certain database table structure, here is the scenario:

I have an “invoices” table, and an invoice can be for a “product” or for a “service” (products are in a table, and services in a separate table).

What is the best way to link an invoice to either of those, but also allow adding more options? If it was an invoice for only a product, the table design would be:

id, product_id, amount

But what is the best way for this scenario? I was thinking something like:

id, source_id, invoice_type (product or service), amount

But I thought that it might not be a good idea.

  • 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-26T21:57:59+00:00Added an answer on May 26, 2026 at 9:57 pm

    If there aren’t any differences between product and service invoices, just use one table with an invoice_type field.


    After reading your entire question, what you listed at the end is right. What you should look at is examples of a subclass and superclass.

    Basically, all your fields that are the same can be grouped into one table, then fields that only pertain to a specific type of service can be grouped into its own table. Instead of having 1 or 2 tables, you’ll end up with a max of 3 (a superclass and 2 subclasses where needed), and they will be more normalized.


    Given your example (Note: this is just an example):

    • Superclass:Invoice

      id, invoice_type (product or service), amount, invoice_dt, customer_paid
      
    • Subclass:Product

      invoice_id, msrp, cost, purchase_dt
      
    • Subclass:Services

      invoice_id, duration, extraneous_cost, start_dt, end_dt
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit of a beginner question here: Say I have a block of xml: <root>
Bit confused here, I have an on-demand instance but do I get charged even
bit of a curly one here let me know if you have any ideas..
Bit of a complicated SQL question here. I currently have a SELECT statement which
Bit confused with this one. Basically, I have a column in a table, and
Bit of a strange one here, i have a CCTV system and contacted the
Bit of an open-ended question here, so I'll outline the problem first. We have
Bit of a problem here, basically I have a web address that I use
A bit of a noob question here... I have a javascript function on a
Bit of a newbie question here. I have a form and one of it's

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.