Skip to content
Advertisement

How to use JOIN and SELECT AS together in SQLAlchemy?

I have the two following tables.

Users Table

id name email
32 Hello e@mail.com
23 World p@mail.com

Sales Table

id SellerId CustomerId Amount
4 32 23 25

I want to join the tables in the following way to get this result. Here I want to only get the entries where customer id is equal to 23.

Id SellerId SellerName SellerEmail Amount
4 32 Hello. e@mail.com 25.

And also do another join this way. Here I want to only get the entries where seller id is equal to 32.

id CustomerId CustomerName CustomerEmail Amount
4 23 World p@mail.com 25.

My code for both the tables is

JavaScript

I was able to achieve this using raw SQL with the following

JavaScript

Please help with doing the same using SqlAlchemy Session.

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement