![]() |
VOOZH | about |
In this article, we will discuss how to get value from a table in SQL with the help of SQLAlchemy in Python.
Database used:
👁 Imagepip install SQLAlchemy pymysql
Note: pymysql is a dependency of sqlalchemy which users need to install so as to run our program.
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.
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 (,).
Output: