0o0o0 Posted June 19, 2015 Share Posted June 19, 2015 TABLE A TABLE B TABLE C FRUIT ID FRUIT ID COUNT FRUIT ID COUNT APPLES 1 STAND 1 APPLES 1 10 STAND 2 APPLES 1 20 GRAPES 2 STAND 1 GRAPES 2 10 PEARS 3 STAND 2 PEARS 3 30 ORANGES 4 STAND 1 ORANGES 4 30 STAND 2 ORANGES 4 Looking for a result like so.. APPLES STAND 1 10 STAND2 20 GRAPES STAND 1 10 STAND2 PEARS STAND 1 STAND2 30 ORANGES STAND 1 4 STAND2 Table A holds all the items none missing ever. Then matches ID with TABLE A ( the most important table) then TABLE C ( second most important) to spit out the above I was messing around with LEFT JOINS and RIGHT JOINS then found LEFT OUTER JOIN.. and in SQL box tested some coding that well.... went infinate and the first time in 10 years had to call my hosting to stop it. .....or.... it finally ran its course 3 days later and I dont know if they did really fix anything. Anyhow I figured Id post here to get some help before really hurting the hosting companies server. $query = "SELECT * FROM `TABLEA`, `TABLEB` WHERE TABLEA.ID = TABLEB.ID AND TABLE.Date = CURDATE() ORDER BY TABLEA.Date ASC"; ( Lets just assume theres a date column in tablea as well) I need to successfully and "safely" add table c without throwin it into a infinity loop lol... Thanks. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted June 19, 2015 Share Posted June 19, 2015 The formatting of the post has thrown what you posted all over the place on my end. Could you just post a describe of your tables, and then an example of what you would like the output to be. p.s. - have you thought about setting up a local development environment that won't cripple your hosting company if you make a boo boo? Quote Link to comment Share on other sites More sharing options...
Barand Posted June 19, 2015 Share Posted June 19, 2015 Use code tags if you want things to line up neatly Quote Link to comment Share on other sites More sharing options...
0o0o0 Posted June 19, 2015 Author Share Posted June 19, 2015 Its ok figured it out.. I'll leave it here for whoever else is looking for the same. ( its not really for fruit lol)$query = "SELECT t1.Fruitname, t2.Fruitcount, t3.Fruitcount FROM tableA as t1 LEFT JOIN tableB as t2 ON t1.id = t2.id LEFT JOIN tableC as t3 ON t1.id = t3.id AND t1.Date = CURDATE() ORDER BY t1.Date ASC"; Quote Link to comment 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.