Search code snippets, questions, articles...

SQLAlchemy query to get distinct records from table

To get unique records from one pr multiple columns you can use .distinct() method of SQLAlchemy
db.session.query(
    UserModel.city
).distinct().all()

The query will return the unique values in city column.

Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet