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.
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 aINNER JOIN(Select * from TableB) as bONa.Name = b.NameBut 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 aINNER JOINTableB as bON a.Name = b.Name |
 |
|
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 aINNER JOIN(Query2) as bONa.commonColumn = b.commonColumnQuery1 and Query2 give two different results. |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-24 : 03:05:56
|
select * from(Query1) as aINNER JOIN(Query2) as bONa.Name = b.NameEm |
 |
|
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_DEPOSITFROM AccountMaster as aINNER JOIN TXNMaster as tONa.ACID = t.ACIDWHEREt.TYPE='D'GROUP BY a.ACCOUNTHOLDERNAME) as xINNER JOIN(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_WITHDRAWALFROM AccountMaster as aINNER JOIN TXNMaster as tONa.ACID = t.ACIDWHEREt.TYPE='W'GROUP BY a.ACCOUNTHOLDERNAME) as yON x.ACCOUNTHOLDERNAME = y.ACCOUNTHOLDERNAMEAnything you see wrong here? |
 |
|
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_DEPOSITFROM AccountMaster as aINNER JOIN TXNMaster as tONa.ACID = t.ACIDWHEREt.TYPE='D'GROUP BY a.ACCOUNTHOLDERNAME) as xINNER JOIN(SELECT a.ACCOUNTHOLDERNAME,SUM(t.AMOUNT) TOTAL_WITHDRAWALFROM AccountMaster as aINNER JOIN TXNMaster as tONa.ACID = t.ACIDWHEREt.TYPE='W'GROUP BY a.ACCOUNTHOLDERNAME) as yON x.ACCOUNTHOLDERNAME = y.ACCOUNTHOLDERNAME[code]Em |
 |
|
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. |
 |
|
|
|
|