select a.name + b.name from tb1 a,tb2 b where a.id < b.id
用一個別名表 use Tempdb go --> -->
if not object_id(N'Tempdb..#T') is null drop table #T Go Create table #T([No] int,[Name] nvarchar(1)) Insert #T select 1,N'a' union all select 2,N'b' union all select 3,N'c' union all select 4,N'd' Go Select a.[NO],a.Name +b.Name as[Name] from #T AS a,#T AS b WHERE a.No<b.NO ORDER BY 1 /* NO Name 1 aa 2 ab 3 ac 4 ad */
小三给了个例子,你把tb2换成tb1就行。 自连接
select a.name + b.name from tb1 a,tb1 b where a.id < b.id
select a.name + b.name
from tb1 a,tb2 b
where a.id < b.id
use Tempdb
go
--> -->
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([No] int,[Name] nvarchar(1))
Insert #T
select 1,N'a' union all
select 2,N'b' union all
select 3,N'c' union all
select 4,N'd'
Go
Select a.[NO],a.Name +b.Name as[Name]
from #T AS a,#T AS b
WHERE a.No<b.NO
ORDER BY 1
/*
NO Name
1 aa
2 ab
3 ac
4 ad
*/
小三给了个例子,你把tb2换成tb1就行。
自连接
where a.id < b.id