Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-03
5
Medium Priority
?
926 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

885 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