Combining SQL Data from Multiple Databases

If you want to use tables that are in separate databases then you can still use both sets of data without any special requirements or syntax.

Select
    first_name, middle_name,last_name
From
    databasename.dbo.Employees

UNION ALL

Select
    name_first as first_name, name_middle as middle_name, name_last as last_name
From
    databasename.dbo.Salesman

If the table is in a different instance then there is another step you have to do.  You will have to link the servers together (example).  Then you can use the same syntax.  The only difference is that you add the linkedserverName to the location. For example

Select
    first_name, middle_name,last_name
From
    linkedservername.databasename.dbo.Employees

UNION ALL

Select
    name_first as first_name, name_middle as middle_name, name_last as last_name
From
    linkedservername.databasename.dbo.Salesman

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

David Bauernschmidt

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *


+ 2 = 7

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>