Reputation: 29
I'm using MySQL with Python Flask and trying to do a search query with LIKE concat however I am getting a Syntax error with it or a Type Error if I use different marks around my symbols.
name_search = form.name.data
cursor.execute('SELECT id, name, surname FROM users WHERE surname LIKE CONCAT ('%', '%s', '%')', [name_search])
Upvotes: 0
Views: 143
Reputation: 410
You could add the percentage signs within the variable
cursor.execute("SELECT id, name, surname FROM users
WHERE surname LIKE '{}'".format("%" + name_search + "%"))
Upvotes: 1