作业帮 > 综合 > 作业

sql如何取交集有这样两条sql语句select distinct id from a where id='123'se

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/27 19:37:13
sql如何取交集
有这样两条sql语句
select distinct id from a where id='123'
select distinct id from a where id='456'
我希望能把他们取得他们记录的交集,sql语句该如何写?
错了 应该是这样的
select distinct temid from a where id='123'
select distinct temid from a where id='456
select distinct id from a where id='123' and id in (select distinct id from a where id='456')
不过偶实在没看出select distinct id from a where id='123'这种语句有什么用处. 就你写的来说这二者不可能有什么交集.
如果你的意思是指并集,就应该用select distinct id from a where id='456' or id = '123'
再问: 这样可以 我还想问一下 如果这个id是个参数 有多个这样的id 不是2个 该怎么写呢