P
P
Pavel Melnikov2017-05-04 09:15:33
Python
Pavel Melnikov, 2017-05-04 09:15:33

How to correctly form a query from python to sqlite?

Good afternoon.
I will make a reservation right away that I am extremely superficially versed in both python and sql, so my question can be quite stupid and naive, I apologize.
I have a table in sqlite where one of the columns is
spb
spb
spb
msk
msk
If I run a SELECT DISTINCT city FROM table query directly from sqlite, it will return
spb
msk
How can I run the same query from python?
It is assumed that the connection to the database is correct (other requests are being processed).
I will give my wrong piece of code, maybe it will be easier to suggest.
result = cur.execute('SELECT DISTINCT city FROM table')
Theoretically, it would be possible to get the entire list from the database and do the processing on the python side, but I wanted to use just such an option.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xdgadd, 2017-05-04
@BblKPYTAC

cur.execute('SELECT DISTINCT city FROM table')
result = cur.fetchall()  # или fetchone()
print(result)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question