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
 General SQL Server Forums
 New to SQL Server Programming
 Help with Stored procedure

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-21 : 12:01:07
I want to select from three tables

t16pendall a
t16pendmvt b
natdocfile n

I want to grab the cossn's that are in both tables but only want one listing of cossn's to appear on the screen.

I've tried this but getting incorrect syntax near where

select n.area, n.reg, n.regionname, n.regionacronym as region, n.dist, a.cossn, a.fo, a.flg_cdt, b.cossn, b.mvt_cdt
from
where exist
(select cossn
from t16pendall a
join t16pendmvt b on a.cossn = b.cossn
join natdocfile n on n.doc=a.fo)


Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-10-21 : 12:05:44
select n.area, n.reg, n.regionname, n.regionacronym as region, n.dist, a.cossn, a.fo, a.flg_cdt, b.cossn, b.mvt_cdt
from <FROM WHERE?!?!>
where exist
(select cossn
from t16pendall a
join t16pendmvt b on a.cossn = b.cossn
join natdocfile n on n.doc=a.fo)
Go to Top of Page

michael.appleton
Posting Yak Master

160 Posts

Posted - 2010-10-21 : 12:28:52
http://www.w3schools.com/sql/sql_join.asp
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-21 : 13:25:25
Lamprey that's my problem I don't know which table to put down. I have info coming from all three tables.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2010-10-21 : 13:30:13
Never mind I got rid of the subquery and this works:

select b. cossn, n.area, n.reg, n.regionname, n.regionacronym as region, n.dist, a.cossn, a.fo, a.flg_cdt, b.cossn, b.mvt_cdt
from t16pendmvt b

join t16pendall a on a.cossn = b.cossn
join natdocfile n on n.doc=a.fo
Go to Top of Page
   

- Advertisement -