ChrisCwmbran Posted May 16, 2013 Share Posted May 16, 2013 Hey all, Here is a brief(ish) explanation of my problem. I've omitted all fields that aren't relevant to the query. I have three tables. 1. manufacturer which contains an fields called manufacturerID (type int) and manufacturerName (type varchar). 2. productType which contains fields called productTypeID (type int) and productDescription (type varchar) 3. product which contains fields productID (type int), productName (type varchar), manufacturer (type int) and productType (type int) Now for example, a kind of product type is "Monitor" and that has a productTypeID of 2. I want to list all manufactrurerName where one or more products made by that manufacturer are monitors i.e. all manufacturers who made monitors. I can do this using more than one query but I suspect there is a way of doing this in a single query. Can anyone tell me how this is done please? Thanks in advance! I've been trying to get my head around this for several hours! Chris. Quote Link to comment https://forums.phpfreaks.com/topic/278083-cant-get-my-head-around-this/ Share on other sites More sharing options...
Jessica Posted May 16, 2013 Share Posted May 16, 2013 It's called a JOIN Quote Link to comment https://forums.phpfreaks.com/topic/278083-cant-get-my-head-around-this/#findComment-1430566 Share on other sites More sharing options...
ChrisCwmbran Posted May 16, 2013 Author Share Posted May 16, 2013 (edited) Thanks. Before I read your post I was thinking along the lines of: SELECT * FROM manufacturer m WHERE m.manufacturer IN (SELECT p.manufacturer FROM product p WHERE p.productType=2); But I don't think that's a join - and its close to midnight here so my brain is starting to melt. I'll read up on joins. I did lots of SQL training with Oracle but that was 22 years ago and I haven't used it at all since! Thanks for your response! Edited May 16, 2013 by ChrisCwmbran Quote Link to comment https://forums.phpfreaks.com/topic/278083-cant-get-my-head-around-this/#findComment-1430567 Share on other sites More sharing options...
Barand Posted May 17, 2013 Share Posted May 17, 2013 SELECT DISTINCT m.manufacturerName FROM manufacturer m INNER JOIN product p ON p.manufacturer = m.manufacturerID WHERE p.productType = 2 Quote Link to comment https://forums.phpfreaks.com/topic/278083-cant-get-my-head-around-this/#findComment-1430582 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.