flask sqlalchemy query specific columns

To query specific columns using Flask-SQLAlchemy, you can follow these steps:

  1. Import the necessary modules:
from yourapp import db
from yourapp.models import YourModel
  1. Use the query method to select specific columns:
result = db.session.query(YourModel.column1, YourModel.column2).all()
  1. Access the specific columns in the result:
for row in result:
    print(row.column1, row.column2)