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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:14:45+00:00 2026-05-26T22:14:45+00:00

I have a database that stores components in a component table. There is a

  • 0

I have a database that stores components in a component table.
There is a second table for component prices. This table has a field that maps to a component id. My price table needs to store information for a bunch of different prices (10, 100, 1000, 10K, 100K, 1M). The thing is, there is a possibility in the future to store other price types such as 25K or 50K.

As of right now, my price table looks like this:

id    component_id    type    price

where the type can take values from 1-6 currently. This is good because it will allow me to add new price types in the future very easily.

The other option is a price table that looks like this:

id    component_id    price_10    price_100    price_1000    price_10K    price_100K    price_1M

But in this case, I would need to add a new field every time a new price type is added.

I hope that people here would agree with the first method.

But using the first method, I’m having trouble displaying a page that would display all my components in my database with the 6 prices it may or may not have (should show 0 in this case). Obviously this would be simple using the second method.

This is the query I have so far:

SELECT * FROM `component` LEFT JOIN `component_cost` ON `cmpcst_component` = `cmp_id`

EDIT:
I thought I would show some sample data from the component price table:
The prices are a unit price for an amount X. X ranges from 10 to 1 million. So I might have something like this in my component price table:

id    component_id    type    price
1     1               1       0.50
2     1               2       0.45
3     1               3       0.40
4     1               4       0.35
5     1               5       0.32
6     1               6       0.30
  • 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-26T22:14:46+00:00Added an answer on May 26, 2026 at 10:14 pm

    The first option its much better.

    For display the data, create a view with a pivot table.

    You can found help here
    http://en.wikibooks.org/wiki/MySQL/Pivot_table

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

Sidebar

Related Questions

I have a distance field in my database that stores the distance traveled on
Ok I have a table in my SQL Server database that stores comments. My
I have a component that i want to store to an SQLite database. public
I have a database that stores dates broken into int's. I.e. Day, Month and
I have a sql database that stores some documents. A user can sign into
I have a MySql database that stores a timestamp for each record I insert.
Our scenario: We have a main database that stores company-wide information. We have several
i have taken over a database that stores fitness information and we were having
I have an application that stores images in a database. Now I have learned
My program has a component - dubbed the Scheduler - that lets other components

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.