There are list1 and list2, each contains 1,104,824 values
table1 has 350,000,000 rows with 3 columns: ID, name1, name2
and this is what I tried to do:
con = mdb.connect('localhost','user','password','db')
cur = con.cursor()
for i in range(1104824)
sql ="select count(distinct(a.ID)) from (select name1 ,ID from table1 where name2 <> '"+str(list1[i])+"') as a where a.name1 = '"+str(list2[i])+"'"
cur.execute(sql)
data = cur.fetchone()[0]
but it is very very slow. Is there any faster way to do this query?