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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:30:23+00:00 2026-05-14T21:30:23+00:00

I am building a database similar to the one described here where I have

  • 0

I am building a database similar to the one described here where I have products of different type, each type with its own attributes.

I report a short version for convenience

product_type
============
product_type_id INT
product_type_name VARCHAR

product
=======
product_id INT
product_name VARCHAR
product_type_id INT -> Foreign key to product_type.product_type_id
... (common attributes to all product) 

magazine
========
magazine_id INT
title VARCHAR
product_id INT -> Foreign key to product.product_id
... (magazine-specific attributes)

web_site
========
web_site_id INT
name VARCHAR
product_id INT -> Foreign key to product.product_id
... (web-site specific attributes)

This way I do not need to make a huge table with a column for each attribute of different product types (most of which will then be NULL)

How do I SELECT a product by product.product_id and see all its attributes?
Do I have to make a query first to know what type of product I am dealing with and then, through some logic, make another query to JOIN the right tables? Or is there a way to join everything together? (if, when I retrieve the information about a product_id there are a lot of NULL, it would be fine at this point).

Thank you

  • 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-14T21:30:23+00:00Added an answer on May 14, 2026 at 9:30 pm

    You could do it all in one query, a few columns would stay empty:

    SELECT
      t.product_type_name,
      t.product_type_id 
      p.product_id,
      p.product_name,
      p.[common attributes to all products...],
      m.*,
      w.*
    FROM
      product p
      INNER JOIN product_type t ON t.product_type_id = p.product_type_id
      LEFT  JOIN magazine     m ON m.product_id      = p.product_id
      LEFT  JOIN web_site     w ON w.product_id      = p.product_id
    WHERE
      p.product_id = ?
    

    Use product_type_id in your app to determine which columns of the result set are interesting to you in any particular case.

    As far as performance goes, this should run pretty quickly (foreign keys, indexes); and it produces a consistent result set for any product type.

    I would recommend against using .* and for explicitly listing every column name, this is more portable, more maintainable and less error-prone.

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

Sidebar

Related Questions

I'm building an article system, and each article will have one more Tags associated
i am building webapp similar to facebook. I want to query the database so
Scenario I am building a database that contains a series of different tables. These
I'm building a database for making hotel reservations. One table called reservations holds the
I'm working on building a database to manage project assignments, and the one part
I am building a web application and have opted to use similar table and
I'm building a public website which has its own domain name with pop/smtp mail
I'm building a native app tha all its entities should commadate in sqlite database.
I have two databases Database 1: (Allows users to add posts similar to a
I have a query that I'm building for an application. The database is 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.