怎么依据前一个SQL语句的结果,决定后一个语句传入参数

MySql 码拜 8年前 (2016-02-07) 750次浏览
小白求帮助,问题可能有点蠢,还是希望有高手来解决一下。
语句1:select myId from B
语句3:select myId from C
语句2:select * from A where id in (语句1的结果(假如语句1没有查到的条目数<1时,用语句3的结果))
最后要得到语句2的查询结果
解决方案

20

引用 2 楼 gikod 的回复:
select * from A where id in (
  select myId from B
  union
  select myId from C where not exists (select myId from B)
)

本人给的这个解决方法就是你想要的吧?
(exist少谢了一个s)


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么依据前一个SQL语句的结果,决定后一个语句传入参数
喜欢 (0)
[1034331897@qq.com]
分享 (0)