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

Left and Right join #61

Closed
sandesh-kulkarni opened this issue Jun 30, 2017 · 10 comments
Closed

Left and Right join #61

sandesh-kulkarni opened this issue Jun 30, 2017 · 10 comments

Comments

@sandesh-kulkarni
Copy link

Is there a way to create left (outer or inner) join and right (outer or inner) join statements?

@twheys
Copy link
Contributor

twheys commented Jul 5, 2017

Yes, when chaining the join function, there is a kwarg called how which takes a pypika.JoinType value

@twheys twheys closed this as completed Jul 5, 2017
@dabaus
Copy link

dabaus commented Nov 1, 2019

OMG why not just make an innerJoin function and leftJoin function?
Then you have covered 95% of all usecases for joins.

@twheys
Copy link
Contributor

twheys commented Nov 1, 2019

Because we have real use cases for right and outer joins as well. A single function with a join type argument resulted in less code which was easier to maintain.

@dabaus
Copy link

dabaus commented Nov 1, 2019

But it creates more complicated code for people using the framework.
I mean, the purpose of this framework was to make it easier for people to write queries instead of using strings. But in this case, this framework results in more complicated code than SQL, so it defeats it's own purpose.

@airtonzanon
Copy link
Contributor

It would be nice to have the functions innerJoin and leftJoin (maybe also for rightJoin).
What do you think to create these functions using the join that PyPika already have?
It would be a small improvement and, maybe will leave the code clearer.

@dabaus
Copy link

dabaus commented Nov 1, 2019

@airtonzanon Yes it would be nice to have a "syntax sugar" for the most common join types.
I spent some time googling the docs, and then eventually i found out how to make a left join from searching the code on github. It could be easier.

@twheys
Copy link
Contributor

twheys commented Nov 1, 2019

Query
  .from_(table)
  .join(table2, JoinType.left)
  .on(...)

vs .

Query
  .from_(table)
  .left_join(table2)
  .on(...)

I don't really see how the code is any more complicated from API perspective, but definitely not opposed to having some extra join functions that call join passing in the JoinType enum. Feel free to raise a PR, i'll have a look right away.

@twheys
Copy link
Contributor

twheys commented Nov 1, 2019

@dabaus I will look at improving the docs so ensure that the join types are clearly covered.

@airtonzanon
Copy link
Contributor

Nice thing @twheys .

@dabaus Do you want to implement it? I can help if you want, or create the PR. It's your call.

Also, I think, with this PR, we could improve the Documentation of this place. If we try to improve the docs bit a bit, we'll have everything updated.

@twheys
Copy link
Contributor

twheys commented Nov 1, 2019

#348
While writing the docs, I figured it wouldn't take more thn a couple of minutes to add these functions. Mind taking a look at seeing if it meets your expectations?

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

4 participants