-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to do "SELECT EXISTS(SELECT 1 FROM ...)"? #619
Comments
These are methods for adding conditions. |
I am looking for something similar, but in my case it is: select
case when exists (select * from sessions where user_id = u.id) then 1 else 0 end is_current
from users u So I am literally would like to include any query into the raw query, like: query.SelectRawFormat("case when exists {0} then 1 else 0 end is_current", sub_query) So the approach could be more flexible, eg: query.SelectRawFormat("case when exists {0} then ? when exists {1} then ? else 0 end is_current",
formats: new object[] { sub_query1, sub_query2 },
bindings: new object[] { 1, 2 }) as a current workaround is: select
case when s.user_id is not null then 1 else 0 end is_current
from users u
left join (select user_id from sessions group by user_id) s on s.user_id = u.id |
Maybe need to add method query.AsExists() or any other for do this?
The text was updated successfully, but these errors were encountered: