Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 27th, 2006, 01:59 PM
Authorized User
 
Join Date: Jun 2006
Location: , , India.
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default Selecting from 2 different databases

Hello Folks,

              I have to select data from 2 different tables & 2 different databases, i am writing the following SQL. Its not working.

SELECT code1 FROM db1.dbo.tbl1
JOIN db2.dbo.tbl2.code2 ON db1.dbo.code1=db2.dbo.tbl2.code2

where
db1=database1;tbl1=table1 in db1;code1=fieldname in tbl1
db2=database2;tbl2=table2 in db2;code2=fieldname in tbl2

Please correct it.

Regards
gags!

  #2 (permalink)  
Old June 27th, 2006, 03:00 PM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try

Code:
SELECT code1 FROM db1.dbo.tbl1 
JOIN db2.dbo.tbl2.code2 ON db1.dbo.tbl1.code1=db2.dbo.tbl2.code2

  #3 (permalink)  
Old June 27th, 2006, 04:30 PM
Authorized User
 
Join Date: Jun 2006
Location: , , India.
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to gagansharma7
Default

Yeah, i missed tbl1 there, i tried & it......didnt work.
It gives arror: db2 not found in sysservers
Do i need to use sp_addlinkedserver?

Thanks

  #4 (permalink)  
Old June 28th, 2006, 03:41 AM
Authorized User
 
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting MAX Value nirmal_s19 SQL Server ASP 1 May 8th, 2007 01:04 AM
help in selecting elements spandit XSLT 1 April 9th, 2007 07:27 PM
Conditional selecting Broodmdh SQL Server 2000 4 August 16th, 2006 12:22 PM
Selecting elements up until a certain one Frode XSLT 5 January 19th, 2006 01:22 PM
Selecting once where there are many onlyu2 MySQL 1 March 25th, 2004 06:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.