Link to home
Start Free TrialLog in
Avatar of jaselee
jaselee

asked on

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

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?
ASKER CERTIFIED SOLUTION
Avatar of vkaushik
vkaushik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 !

Avatar of namasi_navaretnam
CREATE VIEW MyVIEW AS
SELECT userid, password
FROM Database01..user
UNION ALL
SELECT userid, password
FROM Database02..user


Now

Select * from MyView