如何在a,b,c三张表中查一条记录'1'?他们有相同的字段code

gan_lg 2006-02-10 04:40:42
如何在a,b,c三张表中查一条记录'1'?他们有相同的字段code
...全文
78 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
-狙击手- 2006-02-10
  • 打赏
  • 举报
回复
declare @t table([code] int)
declare @t1 table([code] int)
declare @t2 table([code] int)
insert @t select 1 union select 2
insert @t1 select 11 union select 12
insert @t2 select 21 union select 22
select * from
(select code from @t
union
select code from @t1
union
select code from @t2) a
where a.code = 1


/*
code
-----------
1

*/
-狙击手- 2006-02-10
  • 打赏
  • 举报
回复
select aa.* from (select code from a union select code from b union select code from c)
as aa where code = '1'

34,590

社区成员

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

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