-
Notifications
You must be signed in to change notification settings - Fork 174
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
Multiple joins in one query #865
Comments
As an initial step, maybe avoid aliases if possible e.g. SELECT `LHS`.`x` AS `x`, `a`, `b`
FROM `df1` AS `LHS`
LEFT JOIN `df2` AS `RHS`
ON (`LHS`.`x` = `RHS`.`x`) could be SELECT `df1`.`x` AS `x`, `a`, `b`
FROM `df1`
LEFT JOIN `df2` ON (`df1`.`x` = `df2`.`x`) It's probably much less important to avoid nested queries for semi/anti joins, since I think it's much rarer to use multiple in one query. |
Good idea, this is done in PR #892. |
Another random thought: when we have to use aliases, it'd be cool to use |
Nice, I like that!
For allowing multiple queries we kind of need that anyway, so this is not a big deal. |
In databases one often needs to join multiple tables. In dbplyr this produces rather many nested queries which one would more often write as a single query.
Example
Created on 2022-05-10 by the reprex package (v2.0.1)
Currently produces
It would be nicer if it could produce something like
Thoughts & Questions
x_as
andy_as
. I think if they are not provided it might make more sense to not use a table alias.x_as
is provided in a join which is not the first join, then maybe a subquery should be generatedy_as
is provided it can always be usedFULL JOIN
can be tricky to combine with other joins:FULL JOIN
coalesce()
semi_join()
oranti_join()
is followed byleft/right/inner/full_join()
they cannot be combined becauseWHERE
is evaluated afterJOIN
So, I think that
left_join()
andinner_join()
can be combined in one querysemi_join()
andanti_join()
might be combined (though nested queries might be more efficient)The text was updated successfully, but these errors were encountered: