SQL Server/T-SQL Tutorial/Table Join/MERGE

Материал из SQL эксперт
Перейти к: навигация, поиск

INNER MERGE JOIN

3> SET NOCOUNT ON;
4> USE tempdb;
5> GO
Changed database context to "tempdb".
1> DROP TABLE dbo.T1, dbo.T2;
2> GO
1> CREATE TABLE dbo.T1(col1 INT PRIMARY KEY);
2> CREATE TABLE dbo.T2(col1 NUMERIC(12, 2) PRIMARY KEY);
3>
4> INSERT INTO dbo.T1(col1) VALUES(1);
5> INSERT INTO dbo.T1(col1) VALUES(2);
6> INSERT INTO dbo.T1(col1) VALUES(3);
7>
8> INSERT INTO dbo.T2(col1) VALUES(1.);
9> INSERT INTO dbo.T2(col1) VALUES(2.);
10> INSERT INTO dbo.T2(col1) VALUES(3.);
11>
12> SELECT T1.col1, T2.col1
13> FROM T1 INNER MERGE JOIN T2
14>   ON dbo.T1.col1 = dbo.T2.col1;
Warning: The join order has been enforced because a local join hint is used.
col1        col1
----------- --------------
          1           1.00
          2           2.00
          3           3.00