whit3fir3 Posted December 8, 2009 Share Posted December 8, 2009 I am working on a project and I am having problems with a JOIN statement. The following statement pulls information from a total of 5 tables. The first 4 joins work exactly like I was them to. It is the join with the Img table that I giving me problems. The Img table is designed to store images related to the corresponding record in the table Cards. I wanted it to be a One to Many relationship so that each card record could have multiple images. The problem I am having is when a Card record has multiple images images that Card record is being repeated. This is not what I want it to do. I just want it to show up once. Does anyone know what I am doing wrong with my JOIN statement? SELECT t1.id as 'id',t3.name as 'Brand',t2.Name as 'Sport',t1.fname,t1.lname, t1.cardnum,t1.year1,t1.year2,t1.price,t1.qty,t4.cond as 'Cond',t1.beckett_price, t1.price_paid as 'paid', t5.landscape as landscape FROM `Cards` as t1 INNER JOIN `Sports` as t2 on t2.id=t1.sportID INNER JOIN `Brand` as t3 on t3.id=t1.brandID INNER JOIN `Con` as t4 on t4.id=t1.cond LEFT OUTER JOIN `Img` as t5 on t5.cardID=t1.id ORDER BY id DESC LIMIT 100 Thanks, Whit3fir3 Quote Link to comment https://forums.phpfreaks.com/topic/184361-assistance-with-mysql-join-statement/ Share on other sites More sharing options...
mwasif Posted December 8, 2009 Share Posted December 8, 2009 Apply GROUP BY on t1.id SELECT t1.id as 'id',t3.name as 'Brand',t2.Name as 'Sport',t1.fname,t1.lname, t1.cardnum,t1.year1,t1.year2,t1.price,t1.qty,t4.cond as 'Cond',t1.beckett_price, t1.price_paid as 'paid', t5.landscape as landscape FROM `Cards` as t1 INNER JOIN `Sports` as t2 on t2.id=t1.sportID INNER JOIN `Brand` as t3 on t3.id=t1.brandID INNER JOIN `Con` as t4 on t4.id=t1.cond LEFT OUTER JOIN `Img` as t5 on t5.cardID=t1.id GROUP BY t1.id ORDER BY id DESC LIMIT 100 Quote Link to comment https://forums.phpfreaks.com/topic/184361-assistance-with-mysql-join-statement/#findComment-973566 Share on other sites More sharing options...
whit3fir3 Posted December 8, 2009 Author Share Posted December 8, 2009 That solved it. Thank you for the assistance mwasif. I will have to read up on 'GROUP BY ' in case I run into this again. Quote Link to comment https://forums.phpfreaks.com/topic/184361-assistance-with-mysql-join-statement/#findComment-973835 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.