How to check if a subquery has exactly one distinct result and a specified value concisely?
-
30-10-2019 - |
题
I found myself writing the following:
select 'yes'
where exists(select * from foo where val=1)
and not exists(select * from foo where val<>1);
and wondering if there is a more concise way without sacrificing too much readability.
I found one way which I am posting as an answer but I'm not entirely happy with it and would be very interested in alternatives
In this case val
is unique within foo
- there are no duplicates
没有正确的解决方案
不隶属于 dba.stackexchange