默认查询出来的字段只有第1个表的字段名,所以无法分辨,这时要虚构出一个字段用来判别是哪个表的。。
select infotitle,infoid,content,infotime,'table_a' as Info FROM [bds0020003_db].[dbo].[Info] where infotitle like '%基地%' or content like '%基地%' UNION ALL select newstitle,newsid,content,newstime,'table_b' as news FROM [bds0020003_db].[dbo].[news] where newstitle like '%基%' or content like '%基%' order by infotime desc
搜索包含'基地'关键词的多源信息
本文展示了如何通过SQL查询从两个不同的数据库表中检索包含关键词'基地'的内容,并将结果按照时间倒序排列。通过使用UNION ALL语句合并查询结果,实现了一次性的数据整合。
884

被折叠的 条评论
为什么被折叠?



