Hi.

I know that , there are many solutions for merge/union SQL statements. But I did not get the correct result that I want. I want to union 4 different SQL statements that shows its name and total. It means that the table will consists of 2 columns and 5 rows including the header text.

how to rearrange the queries so that it will shown two columns (Type Overdue and Total Overdue Collection) with 4 rows consist of (Total Charged Overdue, Total Interest Overdue, Total Penalty Overdue, Total Principal Overdue with their total) like the example below

Type Total
Total Overdue 1000.00
Total Charged 55.01
Total Interest 20.14
Total Penalty 5947

Thank you.

**What I have tried:**
First query that i tried is

select (SELECT SUM([Total Interest Overdue(MYR)]) AS [Total Interest Overdue(MYR)] FROM (SELECT SUM(l.interestOverdue) * d.bidspotrate AS [Total Interest Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode GROUP BY d.bidspotrate) AS [Total in MYR]) as [Total Interest Overdue],

(SELECT SUM([Total Penalty Overdue(MYR)]) AS [Total Penalty Overdue(MYR)] FROM (SELECT SUM(l.penaltyOverdue) * d.bidspotrate AS [Total Penalty Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode WHERE (l.source = 'Excel ') GROUP BY d.bidspotrate) AS [Total in MYR]) as [Total Penalty Overdue],

(SELECT SUM([Total Principal Overdue(MYR)]) AS [Total Principal Overdue(MYR)] FROM (SELECT SUM(l.principalOverdue) * d.bidspotrate AS [Total Principal Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode GROUP BY d.bidspotrate) AS [Total in MYR]) as [Total Principal Ovedue],

( select sum([Total Charged Overdue(MYR)]) as

[Total Charged Overdue(MYR)] from (select (SUM (l.chargedOverdue) * d.bidspotrate) as

[Total Charged Overdue(MYR)] from loan l, danadb d where l.currency=d.ccycode group by d.bidspotrate) as [Total in MYR]) as [Total Charged Overdue]

The result of this queries show 4 column with two rows.

Total Overdue Total Charged Total Interest Total Penalty
1000.00 55.01 20.14 5747

And I tried another queries

select (SELECT SUM([Total Interest Overdue(MYR)]) AS [Total Interest Overdue(MYR)] FROM (SELECT SUM(l.interestOverdue) * d.bidspotrate AS [Total Interest Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode GROUP BY d.bidspotrate) AS [Total in MYR]) union

(SELECT SUM([Total Penalty Overdue(MYR)]) AS [Total Penalty Overdue(MYR)] FROM (SELECT SUM(l.penaltyOverdue) * d.bidspotrate AS [Total Penalty Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode WHERE (l.source = 'Excel ') GROUP BY d.bidspotrate) AS [Total in MYR]) union

(SELECT SUM([Total Principal Overdue(MYR)]) AS [Total Principal Overdue(MYR)] FROM (SELECT SUM(l.principalOverdue) * d.bidspotrate AS [Total Principal Overdue(MYR)] FROM Loan AS l INNER JOIN Danadb AS d ON l.currency = d.ccycode GROUP BY d.bidspotrate) AS [Total in MYR]) union

( select sum([Total Charged Overdue(MYR)]) as

[Total Charged Overdue(MYR)] from (select (SUM (l.chargedOverdue) * d.bidspotrate) as

[Total Charged Overdue(MYR)] from loan l, danadb d where l.currency=d.ccycode group by d.bidspotrate) as [Total in MYR])

The result of the second query show only one column with 5 rows.

Total
1000.00
55.01
20.14
5947

Below is the desired output that I want :

There are two columns: type and total

Type Total

Total Overdue 1000.00

Total Charged 55.01

Total Interest 20.14

Total Penalty 5947