Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Draw two tables from different database on a single SQL command?

Posted on 2003-11-03
5
912 Views
Last Modified: 2012-08-14
How do I grab two database record and display them on a single go? For example I'm trying to draw two database userid + password.

1. Database01 - table name: user - column: userid/password
2. Database02 - table name: user - column: userid/password

Can I use view to pull both of the tables from different database and put them on a single SQL command? I tried but it keep coming with INNER JOIN function which I don't need. Any suggestions?
0
Comment
Question by:jaselee
5 Comments
 
LVL 1

Accepted Solution

by:
vkaushik earned 125 total points
ID: 9676834
Hi,
  You can use the following sql to retrieve different records from different databases in a single go

select dbid from udb01.usr.defect
union
select dbid from udb02.usr.defect

where dbid is a column name, udb01/udb02 are the 2 diff databases, usr is the user table user and defect is the table name.

Use union to get the data.

You will need to modify the sql to get the desired result.

Cheers,
Kaushik

0
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 9677098
Use <Database>.dbo.<Table> on Query
Ex:
SELECT userid, password
FROM Database01.dbo.user
UNION ALL
SELECT userid, password
FROM Database02.dbo.user

OR you can use join !

0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9678837
CREATE VIEW MyVIEW AS
SELECT userid, password
FROM Database01..user
UNION ALL
SELECT userid, password
FROM Database02..user


Now

Select * from MyView
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question