3 tables in a database. Table1 is tabCategory, Table2 is tabSub, Table3 is Parts.
Table3, Parts, is populated with 3 columns, multiple entries, thousands of them. Column1 is the part number, column2 is the Category and column3 is the Type from tabSub.
The user must fill column1 (PartNumber) according to the part number it wants to add in the DB.
He must also enter the Category (PartType) for his part, wich is limited to a list form Table1, tabCategory. He must also enter the SubCategory limited by a list from Table2, tabSub. Table2 is built with some 40 subcategories to which correspond only 10 different categories.
For example: part: DC23, Category:Capacitor, SubCategory:Mylar…if the part was a Transistor the Catgory would be a Semiconductor and the SubCategory could not be Mylar.
The Challenge: How can I make an SQL query that would deliver a list of all the available SubCategory using as a criteria the adjacent field Category chosen by the user?
Something like this (which does not work):
SELECT tabSub.Category, Amplifier.Category
FROM tabSub INNER JOIN Amplifier ON tabSub.Type = Amplifier.PartType
WHERE (((tabSub.Category)=[Amplifier].[Category]));
The goal being to limit the available user choices based on his entry in the Category field for that particular record. This Query result would be used to limit his list of choices.
Thanks for your suggestions. Cheers
Best Answer
You just need to make your tables have the proper Foreign Key Constraints
Some sample data:
You can check it at SQLFiddle
The SQL that gets the list of all possible subcategories, given one category, is straightforward: