15,968,352 members
See more: , +
I have two queries

first -

SQL
```select order_type, sum(order_value)as "Total"
from tpayment_order
group by order_type```

which gives me result as -

SQL
```order_type    Total
C           345439
P           5435
T           787```

Second -

SQL
`select description from order_status_ref`

which gives me result as
SQL
```description
Collection
Payout
Travel Payout```

I want to write a query which will give result as

SQL
```Order_type    description    Total
C              Collection    4565
P              Payout        4423
T            Travel Payout   456546```

The
SQL
`order_status_ref`
table stores the description for each order type
Posted

## Solution 3

It get solved ---- many thanks.... I have used following query

SQL
```SELECT T.order_type, R.[description], SUM(order_value) AS [Total]
FROM tpayment_order T
INNER JOIN tpayment_order_type_ref R ON T.order_type = R.order_type
GROUP BY T.order_type, R.[description]```

v3

## Solution 2

Use INNER JOIN[^]

## Solution 1

Hi,

Try joining
SQL
```SELECT A.order_type, sum(A.order_value) AS "Total", B.Description
FROM tpayment_order A, order_status_ref B
WHERE A.order_type=B.order_type
GROUP BY order_type, order_status_ref```

But a vital assumption is that the order_status_ref is table with the following mapping:

SQL
`order_type | Description`

Without this mapping, the joining would be meaningless.

vikram_shinde 23-Feb-12 10:39am
yah.. that's the mapping ....
Rajesh Anuhya 23-Feb-12 10:44am
You mean order_status_ref have only one column i.e description??
--RA
[no name] 23-Feb-12 10:41am
Then this query should solve. Do try it!
vikram_shinde 23-Feb-12 10:56am
order_status_ref has two column - order_type and description

Top Experts
Last 24hrsThis month
 Richard Deeming 95 Pete O'Hanlon 85 Luc Pattyn 50 OriginalGriff 23 Member 16338716 10
 OriginalGriff 361 Pete O'Hanlon 265 Dave Kreskowiak 155 merano99 115 Richard Deeming 95

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900