does something like followin exists? ('''select * from TABLE where ? in FIELD''',(VAR))

Viewed 45

does something like followin exist?

('''select * from TABLE where ? in FIELD''',(VAR))

I need to select all table rows where FIELD just contains the text of VAR (so not needed FIELD=VAR) I'm using python3 and sqlite3.

1 Answers

You can use the function INSTR():

sql = "SELECT * FROM tablename WHERE INSTR(FIELD, ?)"

or the operator LIKE:

sql = "SELECT * FROM tablename WHERE FIELD LIKE '%' || ? || '%'"

to get the rows that contain the value of VAR:

execute(sql, (VAR,))
Related