原文在23楼tim_spac:http://topic.youkuaiyun.com/u/20100312/17/70138908-f169-4fa0-ac27-28601ee81c3b.html
select * from t where a = @id
union
select 0 where not exists (select 1 from t where t.a=@id)
本文介绍了一种使用SQL进行数据查询的方法,通过union操作结合子查询来找出特定条件下的数据记录,适用于需要判断某字段是否存在特定值的场景。
原文在23楼tim_spac:http://topic.youkuaiyun.com/u/20100312/17/70138908-f169-4fa0-ac27-28601ee81c3b.html
select * from t where a = @id
union
select 0 where not exists (select 1 from t where t.a=@id)
9630

被折叠的 条评论
为什么被折叠?