Friday, February 24, 2012

How to query two tables from different database

Hi,
I'm trying to query some data from two database (d1.tbl1 and d2.tbl2).
How can I do this? I'm new to SQL.
Thanks in advance,
SarahSELECT t1.col1, t2.col2
FROM database1.dbo.table1 t1
INNER JOIN database2.dbo.table2 t2
ON t1.pkey = t2.fkey
If you give more precise requirements (see my signature) we can give a more
precise answer.
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"SG" <sguo@.coopervision.ca> wrote in message
news:uIQd0H4PFHA.2876@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I'm trying to query some data from two database (d1.tbl1 and d2.tbl2).
> How can I do this? I'm new to SQL.
> Thanks in advance,
> Sarah
>|||Thanks so much for your response. It works.
Sarah
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:%23Kqs$I4PFHA.3336@.TK2MSFTNGP09.phx.gbl...
> SELECT t1.col1, t2.col2
> FROM database1.dbo.table1 t1
> INNER JOIN database2.dbo.table2 t2
> ON t1.pkey = t2.fkey
> If you give more precise requirements (see my signature) we can give a
> more precise answer.
> --
> This is my signature. It is a general reminder.
> Please post DDL, sample data and desired results.
> See http://www.aspfaq.com/5006 for info.
>
>
> "SG" <sguo@.coopervision.ca> wrote in message
> news:uIQd0H4PFHA.2876@.TK2MSFTNGP10.phx.gbl...
>

No comments:

Post a Comment