在SQL 中,有两个表 表 A 中的数据为 code name
a b1
a b2
a b3
a b4 表 B 中的数据为 Code name
a c1
a c2
a c3
a c4
a c5
a c6
a c7请问如果 得到 表 C 的数据为 Code name1 name2
a b1 c1
a b2 c2
a b3 c3
a b4 c4
a c5
a c6
a c7
a b1
a b2
a b3
a b4 表 B 中的数据为 Code name
a c1
a c2
a c3
a c4
a c5
a c6
a c7请问如果 得到 表 C 的数据为 Code name1 name2
a b1 c1
a b2 c2
a b3 c3
a b4 c4
a c5
a c6
a c7
解决方案 »
- 如何通过sql语句来判断sql 2000的一个表是否被锁住了
- 刚学SQL Server 改注意点什么
- 数据拆分
- 用sqlserver自定义函数求得
- SQL 2000中的一个数据库中的表不能写和修改的问题.....
- 如何统计某个以逗号相隔的字段?
- 简单问下count的统计
- 打扰一下 想请教你个问题 sql里面有个字段pay_memo是存放ip地址的如221.199.137.218!001 我想请教一个select语句 只选出221.199.137.218
- [求助]sql2005 安装了 dts2000的设计器组件却不能使用
- 存储过程的问题,对我来说有点难了
- 高分求SQL语句
- sql 统计.在线等....
create table #temp1(code_no1 varchar(50),descript1 varchar(50))
create table #temp2(code_no2 varchar(50),descript2 varchar(50)) insert into #temp1 values('a','b1')
insert into #temp1 values('a','b2')
insert into #temp1 values('a','b3')
insert into #temp1 values('a','b4')
insert into #temp2 values('a','c1')
insert into #temp2 values('a','c2')
insert into #temp2 values('a','c3')
insert into #temp2 values('a','c4')
insert into #temp2 values('a','c5')
insert into #temp2 values('a','c6')
insert into #temp2 values('a','c7') select code_no1 as code_no,descript1,'' as descript2 from #temp1
union
select code_no2 as code_no,'' as descript1,descript2 from #temp2select code_no1 ,descript1,descript2 from #temp1 FULL OUTER JOIN #temp2 on code_no1=code_no2
FULL OUTER JOIN 不行的
create table a(code varchar(10),name varchar(10),id int identity(1,1))
insert a
select 'a', 'b1' union all
select 'a', 'b2' union all
select 'a', 'b3' union all
select 'a', 'b4' create table b(code varchar(10),name varchar(10),id int identity(1,1))
insert b
select 'a', ' c1' union all
select 'a', ' c2' union all
select 'a', ' c3' union all
select 'a', ' c4' union all
select 'a', ' c5' union all
select 'a', ' c6' union all
select 'a', ' c7' select b.code,a.name,b.name from b left join a on a.id=b.iddrop table a
drop table b
code name name
---------- ---------- ----------
a b1 c1
a b2 c2
a b3 c3
a b4 c4
a NULL c5
a NULL c6
a NULL c7(7 row(s) affected)
create table #temp1(code_no1 varchar(50),descript1 varchar(50))
create table #temp2(code_no2 varchar(50),descript2 varchar(50)) insert into #temp1 values('a','b1')
insert into #temp1 values('a','b2')
insert into #temp1 values('a','b3')
insert into #temp1 values('a','b4')
insert into #temp2 values('a','c1')
insert into #temp2 values('a','c2')
insert into #temp2 values('a','c3')
insert into #temp2 values('a','c4')
insert into #temp2 values('a','c5')
insert into #temp2 values('a','c6')
insert into #temp2 values('a','c7') select #temp2.code_no2,#temp1.descript1,#temp2.descript2
from #temp1 right join #temp2 on right(#temp1.descript1,1)=right(#temp2.descript2,1)drop table #temp1,#temp2