join query or union of two results [Resolved]

Posted by Vanchi050585 under Sql Server on 6/30/2010 | Views : 1558 | Status : [Member] | Replies : 2
hi friends,

i have two queries they are:
query1:
select CustID,NoOfChits from tblCust1 where [Group]='A' and CustID='a001'
query2:
select count(TKCustID) as Taken from tblAuctionGroup where [Group]='A' and TKCustID='a001'

Results of 1st query was:
----------
CustID NoOfChits
a001 2

Results of 2nd query was:
----------
Taken
4

But i want to like below:
--------------------------
CustID NoOfChits Taken
a001 2 4

in the above queries, 1st query displayed two columns and 2nd query displayed one column. but i would like to append the both results in single table or single record, i mean all results should be in same row in same result.

Thanks
vanchi

Thanks
tvn



Responses

Posted by: PandianS on: 6/30/2010 [Member] [MVP] Silver

Up
0
Down

Resolved
Hi Vanchi

Good Day

You can try Corelated Subquery (or) PIVOT. But your scenario will work with Corelated Subquery.

Try this...But, I could not tested....

select a.CustID,a.NoOfChits,
(select count(1) from tblAuctionGroup b where b.[Group]=a.[Group] and b.TKCustID=a.CustID) ad Taken
from tblCust1 a where a.[Group]='A' and a.CustID='a001'

Pls get back if have any clarifications...
Cheers

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vanchi050585 on: 6/30/2010 [Member] Starter

Up
0
Down
Thanks friend,

just i copy and paste ur query it will work very fine.

Thanks a lot.
vanchi

Thanks
tvn

Vanchi050585, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response