title: how to store result array of joined table in the row result in mysql?
body: <p>We have 3 tables :</p>
  
  <ol>
  <li>donations</li>
  <li>purposes</li>
  <li>expenses</li>
  </ol>
  
  <p>Donations :</p>
  
  <pre><code>+--------+------+
  | do_id  | name |
  +--------+------+
  |  1     |  A   |
  |  2     |  B   |
  |  3     |  A   |
  |  4     |  D   |
  |  5     |  B   |
  |  6     |  B   |
  |  7     |  A   |
  |  8     |  B   |
  +--------+----- +
  </code></pre>
  
  <p>purposes:</p>
  
  <pre><code>+-------+-------+--------+
  | pu_id | do_id | purpose|
  +-------+-------+--------+
  |   1   |   2   |  abc   |
  |   2   |   2   |  def   |
  |   3   |   2   |  gih   |
  |   4   |   3   |  jkl   |
  +-------+-------+--------+
  </code></pre>
  
  <p>expense :</p>
  
  <pre><code>+-------+-------+---------+
  | ex_id | do_id | expense |
  +-------+-------+---------+
  |   1   |   2   |   abc   |
  |   2   |   2   |   def   |
  |   3   |   2   |   gih   |
  |   4   |   3   |   jkl   |
  +-------+-------+---------+
  </code></pre>
  
  <p>Now i want to make query to get all donations for donor <strong>B</strong> and join <strong>purposes table</strong> to get all purposes related to every <strong>donation_id</strong> then join <strong>expenses table</strong> to get all expenses related to <strong>donation_id</strong> and put all of that in every loop independently something like that </p>
  
  <pre><code>Row number 0
  
  donation_id = 1
  array(purposes)
  array(expenses)
  
  Row number 1
  
  donation_id = 2
  array(purposes)
  array(expenses)
  
  Row number 2
  
  donation_id = 3
  array(purposes)
  array(expenses)
  
  Row number 3
  
  donation_id = 4
  array(purposes)
  array(expenses)
  </code></pre>
  
  <p>This is my try :</p>
  
  <pre><code>SELECT *, (
      SELECT * 
      FROM `donation_purposes` 
      WHERE `donation_purposes`.`dopu_donation_id` = 4
  ) AS `purposes` 
  FROM `donations` 
  WHERE `donation_id` = '4'
  </code></pre>
  
  <p>thanks in advance</p>