Solved

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

Posted on 2003-11-03
5
917 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

751 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