473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiple JOINS and duplicates

I am having a similar problem. I am using Dreamweaver (MySQL, PHP) and their advanced recordset to select the tables and fields. The recordsets are pulling all the pertinent records. However, when a shirt is in two colors and available in 10 sizes, each color repeats 10 times for each size in the dynamic color drop down list, and the 10 sizes are repeated twice for each color in the size drop down list.

This is from the DETAIL page recordset:
Expand|Select|Wrap|Line Numbers
  1. SELECT products.itemID, size.size, color.color, options.option
  2. FROM products
  3. JOIN size  
  4. JOIN linksize  
  5. JOIN color  
  6. JOIN linkcolor  
  7. JOIN options  
  8. JOIN linkoptions  
  9. ON products.itemID=linksize.itemID AND size.ID=linksize.sizeID   
  10. AND products.itemID=linkcolor.itemID AND color.ID=linkcolor.colorID  AND products.itemID=linkoptions.itemID AND options.ID=linkoptions.optionID
  11. WHERE products.itemID=colname 
I originally linked all the tables with the WHERE command because the styleno was a foreign field in every table. MySQL book told me to do it like this, so I did, but it has the same result.

What can I add to this script to only show the sizes (xsm-6xl) one time instead of multiplying for each color.

I can e-mail you the print screens in a Word doc to help you see what I am talking about. The web page is not published yet so I can't give you the link.
Evie

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 2 '08 #1
2 1757
chaarmann
785 Expert 512MB
What you want to do is something logically impossible.
First be aware that you need the color repeats for each size, because it can happen that some sizes are not available for some colors. It could happen for example that only red is available for size L, but yellow and red is available for size S. Now we can do 2 solutions depending on following cases

1.) condition: For every color there is exactly the same shirt-size list. That means all possible combinations of colors and sizes are always existing.
Solution: make one query to get all colors, and a second query to get all sizes.
You cannot get all the needed data in one set, that's what I called logically impossible. In your example you get 2 records back for the possible colors. But you need a least 10 records back for all possible sizes. So how do you want to fill out the size-column of the remaining 8 records? Repeat the colors? Fill in NULL? Both solutions are wrong. If you fill in "NULL" then 8 empty lines were showing up in your selection box. And if you program the option box in a way that you avoid these empty values, then you could have easily programmed the option box in a way to avoid double entries.
If you need to return these 2 queries in one result set (which I would not do), you could use construct "select ... UNION select ... " to do it. You would get back 10+2 = 12 rows instead of 10*2=20 rows, which is good for performance. Like this: Let's say the first query returns [a,b,c,...,color], second query returns [a,b,c,...,size]. Then the result records should look like [a,b,c...,is_color, color_or_size]. Achieve it by joining the queries so that it returns: "[a,b,c,... ,true,color] UNION [a,b,c, ...,false,size]"

2.) condition: for evey color there can be a different shirt-size list.That means not all possible combinations of colors and sizes are existing.
Here you need the "cartesian product", that means you need to return a size list for every color. So you cannot avoid returning 2 *10 records in your example which is a special case then. The normal case would return less records and would be something like: only red is available for size L, but yellow and red is available for size S. Here you would not have 2*2=4 records, but only 2+1=3 records.
In your option-boxes, you cannot avoid programming their behaviour dependent on each other: that means if you select "red", the second option box shows one entry "L" only, but if you select "yellow", the second option box suddenly shows 2 entries: "L" and "S".
You can solve that by creating one option box for each size, and hiding/showing the correct one with javascript. Or better: you only make 2 boxes, but fill the second with data interactivey. That means if you click the first option box, you remove all option items from the second and rebuilt it from the data that you have stored in an array in javascript.

I am having a similar problem. I am using Dreamweaver (MySQL, PHP) and their advanced recordset to select the tables and fields. The recordsets are pulling all the pertinent records. However, when a shirt is in two colors and available in 10 sizes, each color repeats 10 times for each size in the dynamic color drop down list, and the 10 sizes are repeated twice for each color in the size drop down list.

This is from the DETAIL page recordset:
Expand|Select|Wrap|Line Numbers
  1. SELECT products.itemID, size.size, color.color, options.option
  2. FROM products
  3. JOIN size  
  4. JOIN linksize  
  5. JOIN color  
  6. JOIN linkcolor  
  7. JOIN options  
  8. JOIN linkoptions  
  9. ON products.itemID=linksize.itemID AND size.ID=linksize.sizeID   
  10. AND products.itemID=linkcolor.itemID AND color.ID=linkcolor.colorID  AND products.itemID=linkoptions.itemID AND options.ID=linkoptions.optionID
  11. WHERE products.itemID=colname 
I originally linked all the tables with the WHERE command because the styleno was a foreign field in every table. MySQL book told me to do it like this, so I did, but it has the same result.

What can I add to this script to only show the sizes (xsm-6xl) one time instead of multiplying for each color.

I can e-mail you the print screens in a Word doc to help you see what I am talking about. The web page is not published yet so I can't give you the link.
Evie

Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 4 '08 #2
chaarmann
785 Expert 512MB
dear Admin,
this entry is double-posted. (see all 2 posts from eviephillips).
And can you please make it its own topic?
Mar 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe | last post by:
Hey, I'm going to give some background on my situation in case anyone can point out a way around my problem altogether... for the problem itself, please skip to the bottom of the post. thanks....
9
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with...
1
by: mike | last post by:
Hello all, any advice or links to pages about how to have multiple language asp pages? For example, you have a database driven website that you want customers around the world to use. How do...
4
by: adolph | last post by:
I created 2 tables, each with an autonumber primary key. Fields are: ID (autonumber Primary key) Number (single) Color (Text) FName (text)in one table and LName (text)in the other What I'm...
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: headache | last post by:
Greetings. I'm a first time poster, so feel free to clue me in to any protocol I may have inadvertently violated. I have an issue that has arisen where I need to join 3 tables where 2 of the 3...
2
by: narendra vuradi | last post by:
Hi I have a requirement where in i haev to convert the SQL from Oracle to the one which will run on the SQL server. in the Oracle Query i am doing multiple joins, between some 13 tables. and...
2
by: beargrease | last post by:
I'm kind of comfortable with basic joins, but a current project requires a complex query of many tables. The GROUP_CONCAT(DISTINCT ...) function has been very useful as returning my values as comma...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.