本文介绍了如何加入TSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表A和B,
表A.
I have two table A and B,
Table A.
col 1 col 2
Row1 A
Row2 A
Row3 A
Row4 A
Row5 A
Row6 A
表B.
Table B.
col 1 col 2
Row1 B
Row2 B
Row3 B
我需要以下输出
and I need following output
Row1 A
Row1 B
Row2 A
Row2 B
Row3 A
Row3 B
我该怎么做,高级中的thanx ...
how can I do this, thanx in advanced...
推荐答案
select tb1.Col1 , tb2.col2 from tableA as tb1 Inner join
Tableb as tb2 on tb1.col1 = tb2.col1
SQL联接 [ ^ ]
http://blog.sqlauthority.com/2009 /04/13/sql-server-introduction-to-joins-basic-of-joins/ [ ^ ]
最好的问候
M.Mitwalli
SQL Joins[^]
http://blog.sqlauthority.com/2009/04/13/sql-server-introduction-to-joins-basic-of-joins/[^]
Best Regards
M.Mitwalli
CREATE TABLE dbo.Tab1 (Col1 VARCHAR(10), Col2 VARCHAR(10))
CREATE TABLE dbo.Tab2 (Col1 VARCHAR(10), Col2 VARCHAR(10))
INSERT INTO dbo.Tab1 (Col1, Col2)
SELECT 'Row1','A'
UNION ALL
SELECT 'Row2','A'
UNION ALL
SELECT 'Row3','A'
UNION ALL
SELECT 'Row4','A'
UNION ALL
SELECT 'Row5','A'
UNION ALL
SELECT 'Row6','A'
INSERT INTO dbo.Tab2 (Col1, Col2)
SELECT 'Row1','B'
UNION ALL
SELECT 'Row2','B'
UNION ALL
SELECT 'Row3','B'
SELECT T2.Col1,T2.Col2
FROM dbo.Tab2 T2
UNION
SELECT T1.Col1 , T1.Col2
FROM dbo.Tab1 T1
WHERE T1.Col1 IN (SELECT Col1 FROM dbo.Tab2)
这将对您有帮助....
It will helps u....
这篇关于如何加入TSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!