4 Replies - 1662 Views - Last Post: 23 February 2012 - 09:06 AM Rate Topic: -----

#1 vikramsinh_shinde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-February 12

combine result of two sql query

Posted 23 February 2012 - 08:37 AM

I have two queries

first -

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



which gives me result as -

order_type    Total
  C           345439
  P           5435
  T           787




Second -
select description from order_status_ref




which gives me result as

description
Collection
Payout
Travel Payout



I want to write a query which will give result as
Order_type    description    Total 
C              Collection    4565
P              Payout        4423
T            Travel Payout   456546



The
order_status_ref


table stores the description for each order type

Is This A Good Question/Topic? 0
  • +

Replies To: combine result of two sql query

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,298
  • Joined: 12-June 08

Re: combine result of two sql query

Posted 23 February 2012 - 08:52 AM

Just a 'join' then. Join from the payment_order table to the order_status_ref on the common column "order_type" and then display order ref's description!
Was This Post Helpful? 0
  • +
  • -

#3 vikramsinh_shinde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-February 12

Re: combine result of two sql query

Posted 23 February 2012 - 08:54 AM

Could you please write query coz my query is giving error.
Was This Post Helpful? 0
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 205
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: combine result of two sql query

Posted 23 February 2012 - 08:55 AM

You can do this by using the INNER JOIN. You have to have a common field in both tables to actually join them in the first place. More on that here and here

SELECT T.order_type, R.descrip, SUM(order_values) AS [Total]
FROM tpayment_order T
INNER JOIN order_status_ref R ON T.order_type = R.order_type
GROUP BY T.order_type, R.descrip

This post has been edited by nK0de: 23 February 2012 - 08:57 AM

Was This Post Helpful? 1
  • +
  • -

#5 vikramsinh_shinde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 22-February 12

Re: combine result of two sql query

Posted 23 February 2012 - 09:06 AM

I get solved ..... many thanks....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1