VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-get-specific-columns-in-sqlalchemy-with-filter/

⇱ How to get specific columns in SQLAlchemy with filter? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to get specific columns in SQLAlchemy with filter?

Last Updated : 4 Jan, 2022

In this article, we will see how to query and select specific columns using SQLAlchemy in Python.

For our examples, we have already created a Students table which we will be using:

👁 Image
Students Table

Selecting specific column in SQLAlchemy based on filter:

  • To select specific column in SQLAlchemy

Syntax: sqlalchemy.select(*entities)

entities: Entities to SELECT from. This is typically a series of ColumnElement for Core usage and ORM-mapped classes for ORM usage.

  • To filter records in SQLAlchemy

Syntax: sqlalchemy.query.filter(*criterion)

criterion: Criterion is one or more criteria for selecting the records.

Example 1: Selecting specific column based on a single filter

Output:

👁 Image
Output - Example 1

Example 2: Selecting a specific column based on multiple filters

Output:

👁 Image
Output - Example 2
Comment
Article Tags: