Jump to content

[SOLVED] Mysql Using Foreign key to produce results of the joined tables


jkkenzie

Recommended Posts

Hi!,

  I have two tables, one with persons details(members table) and the other with the person's transactions (Shares table). An identifaction number (Primary key) in members table is used in Shares table to hold the transactions of an individual record/members from members table.

 

What i wanted to do is SUM  the total_shares in shares table for each members in members table As i display the results.

 

This involves SELECTING DISTINCT identifaction in shares table, then using the identification one by one to get member's details in members table and getting all transactions (as i SUM) with the same indentification in shares table .

 

This looks simple but when i tried with php Do.....While , it didn't finish the output because the records are in thousands i.e they are very many and thus the page displays few results and gives an error like timeout or server request time exceeded. So i want Mysql to get the results before i display using php.

 

Thanks in advance

Link to comment
Share on other sites

You got the point.

though First, i want to pick All Ids from the Shares table to avoid picking from members table whos Ids dont appear on shares table.

 

Therefore i have  something like :

 

SELECT DISTINCT Id From Shares.

 

Then Use the Ids to pick persons details from members table AND to SUM up the transctions on shares table.

 

I think you SQL was the other way round.

 

I hope this gives you the clear picture.

 

To say it like i have said above looks easy BUT i want a single SQL line of code that does that magic.

 

thanks

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.