导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

求一条查询两个表显示查询语言

mailto520 2007-12-29 01:34:06
有两个表
T1

a b
abcd deeeasfsd
ddfd fdsafd

T2

c d
3fdsf 4333232d

我要将这两个表的查询数据显示为:
a b c d
abcd deeeasfsd
4221 fdaee67

3fdsf 4333232d
ddfd fdsafd
...全文
85 点赞 收藏 13
写回复
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
tim_spac 2007-12-29

DECLARE @t1 table (f1 int, f2 int)
declare @t2 table (c1 char, c2 char)

insert into @t1 values (1,2)
insert into @t1 values (3,4)
insert into @t2 values ('a','b')
insert into @t2 values ('c','d')

select * from @t1 left join @t2 on 1=2
union all
select * from @t1 right join @t2 on 1=2
回复
mailto520 2007-12-29
areswang ,谢谢
回复
areswang 2007-12-29
declare @a table(a varchar(10),b varchar(10))
insert into @a select 'abcd','deeeasfsd'
union all
select 'ddfd','fdsafd'

declare @b table(c varchar(10),d varchar(10))
insert into @b select '3fdsf','4333232d'
union all
select 'ddfd','fdsafd'

select isnull(t1.a,'') a,isnull(t1.b,'') b,''c,''d
from @a t1
union all
select ''a,''b,isnull(t2.c,'') c,isnull(t2.d,'') d
from @B t2
回复
mailto520 2007-12-29
表1(T1)
|----------------|------------------------------|
|字段(a) | 字段(b)
|abcd | deeeasfsd |
|ddfd | fdsafd |
|----------------|------------------------------|

表2(T2)
————————————————————————————
字段(c) 字段(d)
3fdsf 4333232d
ddfd fdsafd
————————————————————————————

我要将这两个表的查询数据希望显示为:
---------------------------------------------------------------------------
字段(A) 字段(B) 字段(c) 字段(D)
abcd deeeasfsd
4221 fdaee67
3fdsf 4333232d
ddfd fdsafd
————————————————————————————————————————————
回复
areswang 2007-12-29
LZ,贴个正确格式出来
回复
mailto520 2007-12-29
areswang chuifengde
你们的方法还是不行
回复
areswang 2007-12-29
declare @a table(a varchar(10),b varchar(10))
insert into @a select 'abcd','deeeasfsd'
union all
select 'ddfd','fdsafd'

declare @b table(c varchar(10),d varchar(10))
insert into @b select '3fdsf','4333232d'
union all
select 'ddfd','fdsafd'

select isnull(t1.a,'') a,isnull(t1.b,'') b,
isnull(t2.c,'') c,isnull(t2.d,'') d from
(select * from @a ) t1
full join
(select * from @b ) t2
on t1.a = t2.c
order by a desc
回复
chuifengde 2007-12-29
??
select isnull(a,'') a,
isnull(b,'') b,
isnull(c,'') c,
isnull(d,'') d,
from t1 full join t2
on t1.a=t2.c
回复
mailto520 2007-12-29
tim_spac
你的方法不行呀
字段都在一起去了
回复
mailto520 2007-12-29
打错了,应该是
有两个表
T1

a b
abcd deeeasfsd
ddfd fdsafd

T2

c d
3fdsf 4333232d
ddfd fdsafd

我要将这两个表的查询数据显示为:
a b c d
abcd deeeasfsd
4221 fdaee67

3fdsf 4333232d
ddfd fdsafd
回复
tim_spac 2007-12-29

select * from T1
union all
select * from T2
回复
pt1314917 2007-12-29
4221 fdaee67

这个从何而来?
回复
hhnick 2007-12-29
看不懂楼主最后显示的数据从那个表来的
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告