Closed spaciandd closed 1 year ago
I think what you need here is FromRaw
https://stackoverflow.com/questions/62890416/using-sqlkata-from-an-existing-query/62910347#62910347
It will produce result like,
select * from (select * from country) innerQuery
Which is not required.
Can you give me a code example of what you expect to see?
Just want to see SQL that I pass e.g.
select * from country where population is not null
If I above query I want Query instance to be created for it.
The FromRaw method makes it subquery which is in efficient as I want to add more filters on top of existing SQL.
So, following is inefficient query,
select * from (select * from country where population is not null) q where capital > 100000
this one is good query,
select * from country where population is not null and (capital > 100000)
So in crux I would like to construct Query based on raw SQL so that I can start building more filters on top of existing one.
Hope it will clarify, thanks.
Thanks for the clarification, but this is not feasible because it requires SqlKata to parse the SQL query and build an object from it, which is something out of the scope of a Query Builder.
I am not sure about your statement that nested query is inefficient from my own testing, I see most modern dbs, are able to optimize the query, and they provide a very similar query plan.
I just use the .SelectRaw("my full raw query with WHERE, GROUP, ORDER BY ETC"), is this what you need ?
I came up with a situation where I have to pass raw sql e.g.
select * from country
. The example I quoted is simpler one, I have complex SQL from which I would like construct Query object.