Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Join Functionality

Author  Topic 

gv_pradeep
Starting Member

19 Posts

Posted - 2008-07-24 : 02:20:46
Hi,
I have two queries giving me two different results. They have a common column. I need to join these tables. Please help me on achieving this. This is how i tried.

(Select * from TableA) as a
INNER JOIN
(Select * from TableB) as b
ON
a.Name = b.Name

But it gives me an error "Incorrect Syntax near the Keyword as"

Thanks,
Jeeves

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-07-24 : 02:45:12

Select a.*,b.* from TableA as a
INNER JOIN
TableB as b
ON a.Name = b.Name
Go to Top of Page

gv_pradeep
Starting Member

19 Posts

Posted - 2008-07-24 : 02:51:38
Sorry. That (Select * from TableA) and (Select * from TableB) were just sample queries that I had given. I am doing complex operations using a couple of tables and getting a result table. Please ignore the specific queries. Consider this.
(Query1) as a
INNER JOIN
(Query2) as b
ON
a.commonColumn = b.commonColumn

Query1 and Query2 give two different results.
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-24 : 03:05:56
select * from
(Query1) as a
INNER JOIN
(Query2) as b
ON
a.Name = b.Name


Em
Go to Top of Page

gv_pradeep
Starting Member

19 Posts

Posted - 2008-07-24 : 03:41:47
Thanks for the reply elan. I've tried the same thing which gives the error as "Incorrect Syntax near the Keyword as".
Here is my query.

(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_DEPOSIT
FROM AccountMaster as a
INNER JOIN
TXNMaster as t
ON
a.ACID = t.ACID
WHERE
t.TYPE='D'
GROUP BY a.ACCOUNTHOLDERNAME) as x

INNER JOIN

(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_WITHDRAWAL
FROM AccountMaster as a
INNER JOIN
TXNMaster as t
ON
a.ACID = t.ACID
WHERE
t.TYPE='W'
GROUP BY a.ACCOUNTHOLDERNAME) as y

ON x.ACCOUNTHOLDERNAME = y.ACCOUNTHOLDERNAME

Anything you see wrong here?
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-07-24 : 03:45:00
yeah, you still didn't put the outer most select in...?

[code]
Select * from

(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_DEPOSIT
FROM AccountMaster as a
INNER JOIN
TXNMaster as t
ON
a.ACID = t.ACID
WHERE
t.TYPE='D'
GROUP BY a.ACCOUNTHOLDERNAME) as x

INNER JOIN

(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_WITHDRAWAL
FROM AccountMaster as a
INNER JOIN
TXNMaster as t
ON
a.ACID = t.ACID
WHERE
t.TYPE='W'
GROUP BY a.ACCOUNTHOLDERNAME) as y

ON x.ACCOUNTHOLDERNAME = y.ACCOUNTHOLDERNAME
[code]

Em
Go to Top of Page

gv_pradeep
Starting Member

19 Posts

Posted - 2008-07-24 : 03:49:39
Ohh ya :( Tat's what i was missing..Thanks a lot :) It works fine.
Go to Top of Page
   

- Advertisement -