I have the following two mysql queries and I'm trying to combine them into one.
Request 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'");
Request 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 tried UNION ALL, but actually it does not work in this case. The problem is that when I echo $DebitAccountName, it also displays the results $CreditAccountName, which I don’t want.
I am using Codeigniter, and in my view file I want to repeat such results.
<?php if(count($records) > 0) { ?>
<?php foreach ($records as $row){ ?>
<?php echo $row['DebitAccountName']; ?>
<?php echo $row['DebitAmount']; ?>
<?php echo $row['CreditAccountName']; ?>
<?php echo $row['CreditAmount']; ?>
Could you help me get two requests in one?
Thanks in Advance :)
source
share