UNION ALL多表搜索查询


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



你可能感兴趣的:(sqlserver)