sql跨数据库查询两个表的方法,加急啊!!

用sql,数据库文件夹下面有两个子数据库
一个是A 一个是B
A中有个表table1,有个字段id1
B中有个表table2,也有字段id2
id1和id2有交叉数据

怎么写sql语句实现,我想用id1做为条件,去查询table2中有ID1字段的数据条、
将数据类型 varchar 转换为 numeric 时出错。

    列出两个表的数据

    select * from [AAA]..Table1 a inner join

    [BBB]..Table2 b on a.id1 = b.id2

    只BBB表里的数据

    Select * from [BBB]..Table2 b where b.id2

    in(Select a.id1 from [AAA]..Table1 a)

    AAA和BBB是数据库名   数据库名和表名之间放两个点

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-27
1.列出两个表的数据
select * from [AAA]..Table1 a inner join [BBB]..Table2 b on a.id1 = b.id2

2.只BBB表里的数据
Select * from [BBB]..Table2 b where b.id2 in(Select a.id1 from [AAA]..Table1 a)

AAA和BBB是数据库名 数据库名和表名之间放两个点本回答被提问者和网友采纳
第2个回答  2009-12-11
oracle可以用datalink,sqlsrver只能用两个sql分别查
第3个回答  2009-12-11
A和B数据库是本地数据库:
Select * from B.dbo.table2 T where T.id2 in(Select distinct ID1 from A.dbo.table1)
第4个回答  2009-12-11
select * from table2 where id2 in (select id1 from table1)
相似回答