Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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
 
Old December 13th, 2005, 10:41 AM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving Data From Multiple Databases

i want to select from many databases, for example , i want to select table
master in database A, and table master in database B.
can i do it like this : " select * from A.Master, B.Master " just like
in SQL Server ??
or can somebody help me how to do that?? Thank
u....


 
Old December 13th, 2005, 10:47 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

select * from a.dbo.master
union all
select * from b.dbo.master

assuming the tables are identical
you will get 1 row for each, if you want combined rows you need to do a join




“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old December 13th, 2005, 03:08 PM
Authorized User
 
Join Date: Oct 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Let me give you an example.Lets say i want to retreve field au_name from table authors in database pubs

AND

field customerid from table customers in database northwind at the same time.

Now what will be the query for that?


 
Old December 13th, 2005, 03:25 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

select distinct a.au_lname,c.customerid
from pubs.dbo.authors a,northwind.dbo.customers c
--what would the join condition be here

select au_lname,'authors' as tablename from pubs.dbo.authors
union all
select customerid ,'customer' as customers from northwind.dbo.customers

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old January 24th, 2012, 04:58 AM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select from multiple (more than 1) databases

Hi guys,
This is great stuff. In my server i have hundreds of databases. How could i select all the info from the exact table in all of the databases?

Thanks!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reporting against multiple databases zaustin Reporting Services 0 July 28th, 2006 02:11 PM
Multiple databases...multiple problems keady2 BOOK: Access 2003 VBA Programmer's Reference 1 June 7th, 2006 01:52 PM
Multiple Hierarchical Databases Macsood Oracle 0 December 6th, 2005 12:47 PM
retrieving multiple rows from table blackbeauty SQL Language 1 August 8th, 2005 03:55 AM
Linking tables with multiple databases jlnash Access 1 August 14th, 2003 07:22 AM





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