Solved

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

Posted on 2003-11-03
5
914 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
[X]
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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

756 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