glennnall Posted October 16, 2010 Share Posted October 16, 2010 ok, i'll ask it this way: i have an inventory of about 700 products, each with an individual part_number, of course, and a list of only, say, three manufacturers: "SKB", "UK" and "ZERO" i'm attempting to learn good normalization technique and i can't decide how to create a manufacturers table to be relational to my part_numbers table. can someone show me, and an example of a query that will return the associated mfr from a list of part_numbers? i'm very grateful gn Quote Link to comment https://forums.phpfreaks.com/topic/216004-relational-tables-help/ Share on other sites More sharing options...
Andy17 Posted October 16, 2010 Share Posted October 16, 2010 I'm not 100% sure I understand what you want. But, if you have a product which has a single manufacturer associated with the product, you can simply have a foreign key in your product table that references a column in a manufacturer table. So, a query could look like this: SELECT * FROM Manufacturer WHERE ManufacturerId = (SELECT ManufacturerId FROM Product WHERE someUniqueColumn = 'someUniqueValue') That would give you the manufacturer details for a given product. As I was reading your post again, it seems like I misunderstood what you wrote, but I hope the above is of any help anyways - otherwise I will have to try again. Quote Link to comment https://forums.phpfreaks.com/topic/216004-relational-tables-help/#findComment-1122717 Share on other sites More sharing options...
glennnall Posted October 16, 2010 Author Share Posted October 16, 2010 thanks, Andy - yep, i wasn't very clear. what i'm looking for is a proper database schema for data like this. i'll worry about the queries once i have a set of relational tables... i'm going to attach an example of the overall database i have that i need to normalize... i'm trying to get help building a set of tables like this properly. thanks much gn [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/216004-relational-tables-help/#findComment-1122750 Share on other sites More sharing options...
glennnall Posted October 16, 2010 Author Share Posted October 16, 2010 anybody...? Quote Link to comment https://forums.phpfreaks.com/topic/216004-relational-tables-help/#findComment-1122834 Share on other sites More sharing options...
ignace Posted October 17, 2010 Share Posted October 17, 2010 SELECT * FROM Manufacturer WHERE ManufacturerId = (SELECT ManufacturerId FROM Product WHERE someUniqueColumn = 'someUniqueValue') Euh... Why need the sub-query? SELECT * FROM manufacturer JOIN product ON manufacturer.id = product.manufacturer_id WHERE product.some_unique_value = 'some_unique_value'; Quote Link to comment https://forums.phpfreaks.com/topic/216004-relational-tables-help/#findComment-1122899 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.