Solved

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

Posted on 2003-11-03
5
908 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:dishanf
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now