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
 How can I run select statement for two tables that

Author  Topic 

akalehzan
Starting Member

21 Posts

Posted - 2007-07-02 : 17:57:18
Hi all,
How can I run select statement for two tables that are on two different databases?


Let's say I have a SQL server 2005 on Windows 2003 server.
On this SQL server 2000 I have two databases.
Let’s say DB1 and DB2. On db1 I have Tbale1 and on DB2 I have Table2.

I like to run a select statment:
Select Table1.*, Table2.* from Table1, Table2
Where table1.id = Table2.id
And Table1.user_name like '%jim%'

Both tables have same architecture.



Thanks for any help.


Abrahim

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-07-02 : 18:01:30
select *
from db1.dbo.Table1 t1
inner join db2.dbo.Table2 t2
on t1.id = t2.id
where t1.user_name like '%jim%'

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

akalehzan
Starting Member

21 Posts

Posted - 2007-12-08 : 02:38:05
Thanks Tara,


Abrahim
Go to Top of Page
   

- Advertisement -