Combining two queries into one without using UNION ALL
00:00 20 Apr 2012

I have the following two mysql queries and I am trying to combine them into one.

Query 1:

$getData = $this->db->query("SELECT *,accounts.name AS DebitAccountName ,debit_side.amount AS DebitAmount
    FROM credit_side
    LEFT JOIN debit_side ON debit_side.transaction_id_dr = credit_side.transaction_id_cr
    LEFT JOIN transaction_info ON transaction_info.transaction_id = credit_side.transaction_id_cr
    LEFT JOIN accounts ON accounts.code = credit_side.account_code 
    WHERE debit_side.account_code='1001'");

Query 2:

 $getData = $this->db->query(SELECT *,accounts.name AS CreditAccountName,credit_side.amount AS CreditAmount
    FROM debit_side
    LEFT JOIN credit_side ON debit_side.transaction_id_dr = credit_side.transaction_id_cr
    LEFT JOIN transaction_info ON transaction_info.transaction_id = debit_side.transaction_id_dr
    LEFT JOIN accounts ON accounts.code = debit_side.account_code 
    WHERE credit_side.account_code='1001'");

I have tried UNION ALL but this is actually not working in this case, The problem is when I echo $DebitAccountName it displays the results of $CreditAccountName as well, which I don't want.

I am using Codeigniter, and in my view file I aim to echo the results like this.

  0) { ?>



 
  

 
  

Would you please kindly help me get the two queries into one?

php mysql codeigniter