How to get value from SQLAlchemy instance by column name? Last Updated : 21 Feb, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to get value from a table in SQL with the help of SQLAlchemy in Python. Database used: Installationpip install SQLAlchemy pymysql Note: pymysql is a dependency of sqlalchemy which users need to install so as to run our program. Get value by column name The given task can be performed by first creating an engine with sqlalchemy, connecting with the database, and executing an SQL query with the connection. The SQL query will contain the name of the column/columns whose values we want and then we will get a result object. The result object will give us all the values when we call fetchall method of the object instance. Python3 from sqlalchemy import create_engine user, password, host, database =\ 'root', '123', 'localhost', 'geeksforgeeks' engine = create_engine( url=f'mysql+pymysql://{user}:{password}@{host}/{database}?charset=utf8') connection = engine.connect() # column name whose values we want table_name = 'student' column_name = 'name,dob' # creating the sql query query = f'SELECT {column_name} FROM {table_name}' # running the query result = connection.execute(query) # fetching all the result and storing in # values variable values = result.fetchall() # printing the output print(values) Output: Output Example 2: Here, if the user wants to get values of multiple columns then you can specify the column names in the query by separating them with a comma (,). Python3 from sqlalchemy import create_engine user, password, host, database =\ 'root', '123', 'localhost', 'geeksforgeeks' engine = create_engine( url=f'mysql+pymysql://{user}:{password}@{host}/{database}?charset=utf8') connection = engine.connect() table_name = 'student' # column names whose values we want column_names = 'name,dob' # creating the sql query query = f'SELECT {column_names} FROM {table_name}' # running the query result = connection.execute(query) # fetching all the result and storing in # values variable values = result.fetchall() # printing the output print(values) Output: Output Comment More infoAdvertise with us Next Article How to insert NULL value in SQLAlchemy? M mycodenotein Follow Improve Article Tags : Python Geeks Premier League Geeks-Premier-League-2022 Python-SQLAlchemy Practice Tags : python Similar Reads How to get column names from SQLAlchemy? In this article, we will discuss how to get column names using SQLAlchemy in Python. SQLAlchemy is an open-source SQL toolkit and object-relational mapper for the Python programming language released under the MIT License. It gives full power and flexibility of SQL to an application. To follow along 3 min read How to select min and max from table by column score in SQLAchemy? In this article, we are going to fetch min and max values from column scores in the SQL table using the SQLAlchemy module. SQLAlchemy is an awesome and easy-to-use python module to connect with SQL and use the features and powers of SQL in python. Here, we are provided with a table that has a column 3 min read How to get specific columns in SQLAlchemy with filter? 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: Students TableSelecting specific column in SQLAlchemy based on filter:To select specific column in SQLAlchemySyntax: sq 2 min read SQL Query to Get Column Names From a Table SQL stands for Structured Query Language. It is a language used to interact with the database, i.e to create a database, to create a table in the database, to retrieve data or update a table in the database, etc. SQL is an ANSI(American National Standards Institute) standard. Using SQL, we can do ma 2 min read How to insert NULL value in SQLAlchemy? In this article, we will see how to insert NULL values into a PostgreSQL database using SQLAlchemy in Python. For demonstration purposes first, let us create a sample table using SQLAlchemy as shown below Creating a table using SQLAlchmey in PostgreSQL:Import necessary functions from SQLAlchemy pack 2 min read How To Select Only One Column Using SQLAlchemy? In this article, we are going to see how to select only one column using SQLAlchemy in Python. SQLAlchemy is a large SQL toolkit with lots of different components. The two largest components are SQLAlchemy Core and SQLAlchemy ORM. The major difference between them is SQLAlchemy Core is a schema-cent 3 min read Like