Jump to content

Some help working with three tables if you can thanks


0o0o0

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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";
 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.