title: Python Script to Execute SQL in Loop
body: <p>I am trying to write python script which calls mysql SQL.</p>
  
  <p>I am relying on first query result to run second query. Problem is that it's throwing error. </p>
  
  <p><strong>Error : cursor2.execute(field_sql,id)</strong></p>
  
  <pre><code>import boto3
  import importlib
  import psutil
  import pymysql
  import pymysql.cursors
  import subprocess
  import sys
  
  rdsConn = pymysql.connect(host = 'XXXX'),
                            db = 'XXXX',
                            user = 'XXXX',
                            password = 'XXXX',
                            charset = 'utf8mb4',
                            cursorclass=pymysql.cursors.DictCursor)
  
  cursor1 = rdsConn.cursor()
  cursor2 = rdsConn.cursor()
  
  
  name = 'Test'
  sql = "select id from Table1 where name = %s"
  cursor1.execute(sql,name)
  result = cursor1.fetchall()
  for id in result:
      field_sql= "select columnname from  Table2 where id = %s"
      cursor2.execute(field_sql,id)
      fieldresult = cursor2.fetchall()
      for fieldrow in fieldresult:
          print(fieldrow)
  
  cursor1.close()
  cursor2.close()
  rdsConn.close()
  </code></pre>