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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:48:35+00:00 2026-06-15T04:48:35+00:00

I’ve been racking my brain trying to figure out how to accomplish a link

  • 0

I’ve been racking my brain trying to figure out how to accomplish a link through foreign keys to help make life easier. I have two tables set up and want to make a 3rd linking to them both adding a couple columns to the 3rd one. here’s the syntax I came up with…

SQL Fiddle (with sample data)

Shirts

CREATE TABLE shirts(
    shirt_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    shirt_name VARCHAR(100) NOT NULL,
    shirt_type VARCHAR(10) NOT NULL,
    shirt_size VARCHAR(20) NOT NULL,
    qp_price_id VARCHAR(20) NOT NULL,
    o_price_id VARCHAR(20) NOT NULL
)ENGINE=INNODB;

Tthere will be more with the V-Necks, Raglan Sleeve, Cap Sleeve etc. shirts….

Price List

CREATE TABLE price_list(
    price_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    price_cat VARCHAR(20) NOT NULL,
    price NUMERIC(6,2) NOT NULL
)ENGINE=INNODB

what I would like to do is create a 3rd table that selects the shirt_name, shirt_type, and shirt_size columns from from the shirts table then create two columns, one being qp_price and the other o_price and make those foreign keys to the price list table to grab the price for that shirt… and I figured maybe using a WHERE clause somehow where the price that shows is controlled by

WHERE shirts.qp_price_id=price_list.price_cat AND shirts.o_price_id=price_list.price_cat

I want to do it this way so I can make price changes as easily as possible to multiple items. This chunk is just for each variety of crewneck shirts I need to represent… there’s more… all the crewneck shirts cost the same price from New Born- 1X adult, so I have those attributed to “crn-qp-a” and “crn-o-a” so if I can just change the price value of “crn-qp-a” ONE TIME and have it automatically update to 20 instances so I don’t have to do it 20 times…. does this make sense?…. please help… lol

  • 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-15T04:48:37+00:00Added an answer on June 15, 2026 at 4:48 am

    You want to, first, remove price information from shirts table and keep it price_list, and then create the third table, and in it you can can link shirts to prices by shirt_id and price_id

    create table shirt_price (
      shirt_id int UNSIGNED not null,
      qp_price_id int UNSIGNED not null,
      o_price_id int UNSIGNED not null,
      primary key (shirt_id, price_id),
      CONSTRAINT shirt_price_ibfk_1 FOREIGN KEY (shirt_id) REFERENCES shirts (shirt_id),
      CONSTRAINT shirt_price_ibfk_2 FOREIGN KEY (qp_price_id) REFERENCES price_list (price_id),
      CONSTRAINT shirt_price_ibfk_3 FOREIGN KEY (o_price_id) REFERENCES price_list (price_id)   
    )ENGINE=INNODB;
    

    So for example, if your shirts table has the following shirts:

    SHIRT_ID    SHIRT_NAME      SHIRT_TYPE  SHIRT_SIZE  
    1           Crewneck Tee    Men         S
    2           Crewneck Tee    Men         M
    3           Crewneck Tee    Men         L
    4           Crewneck Tee    Men         1X
    5           Crewneck Tee    Men         2X
    

    and your price_list table has the following prices:

    PRICE_ID    PRICE_CAT   PRICE
    1           crn_qp_a    27.2
    2           crn_o_a     25.31
    3           crn_qp_b    28.1
    

    Then each shirt will link to 2 prices, one for the qp price, and the other for the o price.

    SHIRT_ID    QP_PRICE_ID   O_PRICE_ID
    1           1             2
    2           1             2
    3           1             2
    4           3             2          
    5           1             2           
    

    To query the price of all men shirts, you do the following:

    select s.shirt_name, s.shirt_type, s.shirt_size, p_qp.price, p_o.price
    from shirts s,
       price_list p_qp,
       price_list p_o,
       shirt_price rel
    where s.shirt_type = 'Men'
      and rel.shirt_id = s.shirt_id
      and rel.qp_price_id = p_qp.price_id
      and rel.o_price_id = p_o.price_id;
    

    Useful Reading:

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this

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.