Skip to content
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 compare results of two subqueries in where clause SQLKata #653

Closed
sterlyukin opened this issue Dec 29, 2022 · 1 comment
Closed

Comments

@sterlyukin
Copy link

I try to compare results of two subqueries in where clause in SQLKata.

In SQL it should be like this:

WHERE (SELECT count(id) FROM main.someTable) = (SELECT count(id) FROM main.anotherTable)

In SQLKata I can compare result of subquery with scalar value:

var mainSubquery = new Query("main.someTable")
            .SelectRaw("count(id)");

var anotherSubquery = new Query("main.anotherTable")
            .SelectRaw("count(id)");

query
    .WhereSub(mainSubquery, "=", 0)

But I can't compare results of two subqueries this way:

query
    .WhereSub(mainSubquery, "=", anotherSubquery)

How can I fix it? Maybe I should execute both of the subqueries and only then compare their results?
Thanks for response in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant