I have a table Transactions, having following columns:
txn_id,
Account_id,
Amount,
txn_id,
txn_type_id
txn_type_id
is the column which shows whether the transaction was CDT
or DBT
, using self join I want to present the records to show the CDT
and DBT
transactions separately
The code I used is :
select
t1.txn_id as DBTAccId,
t1.Account_id as DBTAccountid,
t1.Amount as DBTAmount,
t2.txn_id as CDTId,
t2.Account_id as CDTAid,
t2.Amount as CDTAmount,
t1.txn_type_id
from Transactions t1 , Transactions t2
where t1.txn_id <> t2.txn_id
and t1.txn_type_id = t2.txn_type_id;
But it prints all records for a single txn_id, just like
tx_id txn_type_id
1 CBT
1 CBT
1 CBT
1 CBT
1 CDT
1 CDT
2 CBT
2 CBT
2 CBT
2 CBT
2 CDT
2 CDT
and i want it to print like:
1 CBT
2 CBT
3 CDT
4 CDT