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)
 Query for selecting columns frm different tables

Author  Topic 

bb_anand
Starting Member

13 Posts

Posted - 2004-06-01 : 16:14:51
Hi,
Need to know the syntax for accessing all coluumns on different tables which are on separate databases???? Any idea, pls help!!!

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-06-01 : 16:19:04
Select
A.*, B.*
From db1.dbo.tableA as A
Inner Join db2.dbo.tableB as B
on A.id = B.id
Go to Top of Page

surefooted
Posting Yak Master

188 Posts

Posted - 2004-06-01 : 16:21:40
With no join criteria??


select a.*, b.*
from [database]..[tablename] a, [database]..[tablename]b


With join criteria...


select a.*, b.*
from [database]..[tablename] a join [database]..[tablename]b
on a.[column] = b.[column]


-Jon
Just a starting member.
Go to Top of Page

bb_anand
Starting Member

13 Posts

Posted - 2004-06-01 : 16:22:18
Can we use full Outer Join in place of inner join?
Go to Top of Page

bb_anand
Starting Member

13 Posts

Posted - 2004-06-01 : 16:25:27
what in case if the databases are lying on different servers (hardware)...should I need to define the path of the server too???
Go to Top of Page

bb_anand
Starting Member

13 Posts

Posted - 2004-06-01 : 16:25:31
what in case if the databases are lying on different servers (hardware)...should I need to define the path of the server too???
Go to Top of Page

surefooted
Posting Yak Master

188 Posts

Posted - 2004-06-01 : 16:29:00
You can use any join you like.

To access the tables from different machines, use a fully qualified name [Servername].[Database].[Owner].[tablename] where Servername is a linked server. You can also use open query.

OPENQUERY ( linked_server , 'query' )

-Jon
Just a starting member.
Go to Top of Page
   

- Advertisement -