I am creating a website using Flask and SQLAlchemy. This website keeps track of classes that a student has taken. I would like to find a way to search my database using SQLAlc
query = session.query(Class.title.distinct().label("title"))
titles = [row.title for row in query.all()]
Using the model query structure you could do this
Class.query.with_entities(Class.title).distinct()
As @van has pointed out, what you are looking for is:
session.query(your_table.column1.distinct()).all(); #SELECT DISTINCT(column1) FROM your_table
but I will add that in most cases, you are also looking to add another filter on the results. In which case you can do
session.query(your_table.column1.distinct()).filter_by(column2 = 'some_column2_value').all();
which translates to sql
SELECT DISTINCT(column1) FROM your_table WHERE column2 = 'some_column2_value';
titles = [r.title for r in session.query(Class.title).distinct()]