Reputation: 59
I'm still rather new to querying using Python.
So, I have a connection to a table in SMSS via Visual Studio Code. I took a column from the table, turned it into a dataframe, dropped the duplicates, and stored the result in an array with numPy. Now, my goal is to query and SELECT id FROM [my table] WHERE acc_num IN [my array].
I'm using pandas to query using the connection as well.
I'm a little lost on what the structure of the code should be when trying to access this array that it separate from the database itself. Any help is appreciated.
Upvotes: 0
Views: 1430
Reputation: 524
Try this, Assuming the array name is 'array'
tup_ar = tuple(array.flat)
tup_ar
query = "SELECT name FROM table_name WHERE field IN {}".format(tup_ar)
##Execute the query
Execute the query string created using any of the functions available in python.
Upvotes: 1