Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 13th, 2005, 10:41 AM
Authorized User
 
Join Date: Oct 2005
Location: , , .
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....


Reply With Quote
  #2 (permalink)  
Old December 13th, 2005, 10:47 AM
Authorized User
 
Join Date: Sep 2005
Location: , , .
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/
Reply With Quote
  #3 (permalink)  
Old December 13th, 2005, 03:08 PM
Authorized User
 
Join Date: Oct 2005
Location: , , .
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?


Reply With Quote
  #4 (permalink)  
Old December 13th, 2005, 03:25 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
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/
Reply With Quote
  #5 (permalink)  
Old January 24th, 2012, 04:58 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!!!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:05 AM.


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