python

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?