有什么SQL语句可以把一个表里的两个字段连接起来吗?是"竖"连接.不是:field1+field2连接!!!!!

cgd0282 2006-04-21 06:06:46
例如表:table有十条记录;
连接后结果应该有20条记录:

结果:
fields2
.
.
.
fields2
.
.
.
...全文
789 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaozhao110 2006-12-08
  • 打赏
  • 举报
回复
union
hatelhb 2006-12-08
  • 打赏
  • 举报
回复
借问一下,下列
a 1
b 2
b 4
b 3
c 5
c 7
c 6
c 9
如何得到
a 1
b 243
c 5769
ych3000 2006-12-08
  • 打赏
  • 举报
回复
UP !
liangpei2008 2006-04-22
  • 打赏
  • 举报
回复
UP
hexi0917 2006-04-22
  • 打赏
  • 举报
回复
mark`
  • 打赏
  • 举报
回复
union all
cgd0282 2006-04-22
  • 打赏
  • 举报
回复
好像没去重复处理的.
itblog 2006-04-22
  • 打赏
  • 举报
回复
select * from ta
union all
select * from tb

这样一句,在两个表合并的时候,已经是做去重复处理了,除非你还有其它字段~
cgd0282 2006-04-22
  • 打赏
  • 举报
回复
谢谢各位.现在还想把此字段使用distinct().就是去掉重复的.有什么办法吗?
还有,如果字段多了.这样的语句太长了.会不会有问题?
Visual_Studio_Net 2006-04-22
  • 打赏
  • 举报
回复
去掉重复的,只要把union all 改为union 即可
xeqtr1982 2006-04-22
  • 打赏
  • 举报
回复
去重复的的话用
select field1 from tablename
union
select field2 from tablename
hyrongg 2006-04-21
  • 打赏
  • 举报
回复
create table ta(id int,name nvarchar(5))
insert into ta select 1,'a'
union all select 2,'b'

create table tb(id int,name nvarchar(5))
insert into tb select 3,'C'
union all select 4,'D'

select * from ta
union all
select * from tb

drop table ta
drop table tb
-----------------------

(所影响的行数为 2 行)


(所影响的行数为 2 行)

id name
----------- -----
1 a
2 b
3 C
4 D

(所影响的行数为 4 行)

liangpei2008 2006-04-21
  • 打赏
  • 举报
回复
UP
aniude 2006-04-21
  • 打赏
  • 举报
回复
select column1 from tb
union all
select column2 from tb
marco08 2006-04-21
  • 打赏
  • 举报
回复
同时进行,CSDN服务器不错
2006-04-21 18:09:00

2006-04-21 18:09:00
marco08 2006-04-21
  • 打赏
  • 举报
回复
select 字段1 from 表
union all
select 字段2 from 表
xeqtr1982 2006-04-21
  • 打赏
  • 举报
回复
select field1 from tablename
union all
select field2 from tablename

34,871

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧