I have this query statement:
def search(self, lists): //example input: lists = [1,2,3]
if not self.connected:
self.connect()
for word in lists:
query = self.cur.execute('SELECT InWords FROM Words WHERE Numeric IN (%s)' % (','.join('?'*len(lists))), lists).fetchall()
result = " ".join([x[0] for x in query])
return result
Im using odbc driver to connect in SQL server. In my database, I have 3 columns, Numeric
column ex.1,2,3,4,5
, InWords
column one,two,three,four,five
Now I want to sort the output according to the arrangement of the list
entered to be like this: [one,two,three]
. I observed that the query doesn't display the output according to the input instead whenever the query finds the word from the list
match in database, it will display it. Example I inputed in no particular order the numbers in Numeric
column (3,5,1,2,4)
and the list
variable contains [1,3,2]
, the sql statement display this output: (three,one,two)
instead of [one,three,two]
.