(If you can think of a better title please say)
So I have a database with tables which I want to be able to search. Search as in I have the input intel core i5 and I want to get any row which column Name has intel, core and i5 in it in any arrangement, characters surrounding these words or any other words anywhere.
So far I am doing:
search = "intel core i5" # This is taken from an entry field.
words = []
for word in search.split()
words.append("%" + word.strip() + "%")
results = db_handler.query("""SELECT Table1.ID
FROM Table1
JOIN Table2
ON Table1.ID2 = Table2.ID
WHERE Table2.Name LIKE({0}) AND
Active=1""".format(", ".join("?" for _ in self.words)), self.words)
# db_handler.query is a method which queries and returns results. Plus some other stuff.
# In Table1 there is some columns like ID, ID2, Active, eta
# ID2 matches ID in Table2 which also contains Name
# So I want ID from Table1 searched by Name from Table2
But that does not work as LIKE does not take more than one arg. (There is probably a better way of doing it than splitting the input up but I did this as this was what made sense, is there?) I have seen some people with a bit different questions be suggested REGEXP but I have look at it but did not really get it for my use. If this is the best, can you explain how thanks. How should I do this?
Thanks