UNION ALL多表搜索查询

来源:互联网 发布:千里眼定位软件 编辑:程序博客网 时间:2024/05/16 09:06

默认查询出来的字段只有第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



原创粉丝点击