0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That seems to have worked. I was missing out on using the flat() method.
Cool. Then please accept the solution.

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.