I'm trying to search a database, by iterating through a list of search values. I'm almost there as this works for integers but not strings. The code below won't work, but if I replace the list values with numbers it does:
mycursor = mydb.cursor()
lst = []
select_query = "SELECT * FROM fruit WHERE content LIKE "
ids = ["apple", "pear"]
for x in ids:
var = select_query + str(x)
mycursor.execute(var)
lst.extend(mycursor.fetchall())
print(lst)
LIKE? All fruits where content is exactly equal to'apple'or where it contains the keyword%apple%matching also'pineapple'? Why notWHERE content IN ('apple', 'pear")?