Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a List of Parameters as an Input to a SQL Query

Tags:

python

sql

I have a SQL query that I want want to execute for a list of input parameters.

SELECT Field1, Field2
FROM Table
WHERE Field3 = ?
AND Field4 = ?

I have ~10,000 pairs of values that I want to run this query for. At the moment I'm iterating over the list, and appending each result to a data frame. I feel like there is probably a more Pythonic way to do this. I just don't know what it is.

Is there a cleaner way to do this?

like image 290
Batman Avatar asked Nov 29 '25 18:11

Batman


1 Answers

I think you need to create a temp table that stores the 10,000 pairs of values. Then you can use an Inner Join on that temp table.

Example:

Select f1,f2 
From 
    table t 
    Inner Join temptable m 
        On m.c1 = t.f3 and m.c2(column 2) = t.f4
like image 198
Hlin Avatar answered Dec 01 '25 07:12

Hlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!