1

Here is the code i am using to filter rows with a variable from single column and Its working:

cur.execute("SELECT * FROM Table1 WHERE item1 LIKE ?", ('%'+item_name+'%', ))
n = cur.fetchall()

But i want to filter rows with one variable from multiple columns. For example: Table has three columns as item1, item2 and item3. I want to filter rows as select * from table1 where item1, item2 and item3. If it is possible, please let me know How to do?

1 Answer 1

1

You can join the table to this query:

SELECT '%' || ? || '%' AS item_name

on the conditions that you want, like this:

SELECT t1.* 
FROM Table1 t1 INNER JOIN (SELECT '%' || ? || '%' AS item_name) t2
ON t1.item1 LIKE t2.item_name OR t1.item2 LIKE t2.item_name OR t1.item3 LIKE t2.item_name 

and your code will be:

cur.execute("SELECT t1.* FROM .....", (item_name, ))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.