David542
David542

Reputation: 110163

How to do IN query with a python tuple

I am trying to do the following query:

people = ('mike', 'dave', 'andrew')
cursor.execute('SELECT * FROM peoples WHERE person IN %s', people)

However, this raises a SQL exception. What would be the correct formatting for using an IN *python tuple()* in mysql?

Upvotes: 1

Views: 80

Answers (1)

Haifeng Zhang
Haifeng Zhang

Reputation: 31895

sql_stmt = 'SELECT * FROM peoples WHERE person IN (%s)' % ','.join(map(str,people))

cursor.execute(sql_stmt)

Upvotes: 3

Related Questions