请教一个问题!

giantboy520 2006-01-09 09:09:12
我现在有两个表:
table1:id,title,articles
table2: id,title,articles
我想将两个表的这三个字段都读出来,然后合并成一张表,条件是两个表的:title like '%kyeword%'
请问应该怎么写?
我总是合并不起来!union all
...全文
75 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
giantboy520 2006-01-09
  • 打赏
  • 举报
回复
已经测试成功,谢谢!是数据库问题!出错了!非常感谢
giantboy520 2006-01-09
  • 打赏
  • 举报
回复
我就是写成这样的啊,
select * from table1 where title like '%kyeword%'
union all select * from table2 where title like '%kyeword%'
panjinfu80 2006-01-09
  • 打赏
  • 举报
回复
把语句拿出来分析一下在哪出错?
Ciny_Cou 2006-01-09
  • 打赏
  • 举报
回复
我也可以。是不是你写错了。
-狙击手- 2006-01-09
  • 打赏
  • 举报
回复
select * from table1 where title like '%kyeword%'
union all select * from table2 where title like '%kyeword%'
Ciny_Cou 2006-01-09
  • 打赏
  • 举报
回复
create table #t1(id int,title char(16),articles char(10))
create table #t2(id int,title char(16),articles char(10))

insert into #t1 values(1,'MS-SQL','Microsoft')
insert into #t1 values(2,'Delphi','Borland')
insert into #t2 values(1,'MS-VC++','Microsoft')
insert into #t2 values(2,'C++ Builder','Borland')

select * from #t1
select * from #t2
select a.id,a.title,a.articles from #t1 a where a.title like '%MS-%'union all select b.id,b.title,b.articles from #t2 b
where b.title like '%MS-%'
/*结果
1 MS-SQL Microsoft
2 Delphi Borland

1 MS-VC++ Microsoft
2 C++ Builder Borland

1 MS-SQL Microsoft
1 MS-VC++ Microsoft

*/

drop table #t1
drop table #t2
tiky_6228769 2006-01-09
  • 打赏
  • 举报
回复
你怎么不行了?把你的语句贴出来看看,或者有什么错误也说明出来!这个不难~

34,590

社区成员

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

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