Created
July 15, 2018 00:36
-
-
Save inklesspen/e562915bf4af2eebd1a6e8d3319579d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume these classes are fully defined, including relationships | |
class User(Base): | |
pass | |
class Order(Base): | |
pass | |
# Requested: SELECT DISTINCT user.id FROM user, order WHERE user.id = order.user_id | |
session.query(User.id).select_from(User, Order).filter(User.id == Order.user_id).distinct() | |
# Produces: SELECT DISTINCT user.id AS user_id FROM user, order WHERE user.id = order.user_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment