How to compare two values ​​from different databases in one SQL statement

Do I have an idea to call two values ​​from two different databases and combine them into a single statement? Is it possible? I work with C # and MS-SQL

+3
source share
4 answers

Yes.

For MSSQL, you can add the database name in front of your table. Usually you have 4 namespaces that you can use

<server name>. [database name]. [owner]. [table_name]

So, if you want to compare two values ​​in one of the statements, you will only need to join through the tables, placing the database name in front of the table name.

, , SQL, sql. SQL, - sp_addlinkedserver

+6

:

SELECT
   db1.Value as value1,
   db2.Value as value2
FROM
   [database1].dbo.MyTable1 as db1
   INNER JOIN
   [database2].dbo.MyTable as db2
    ON   
    /* insert join clasue */
+5

. SQL Server, sp_linkedserver. , , , db1 db2 - , dbo - , tab1 tab2 - .

SELECT a.col1 
FROM db1.dbo.tab1 a, db2.dbo.tab2 b
WHERE a.col1 = b.col2
0

SQL Server , , Microsoft JET, .

0

All Articles