title: retrieving data from table based on a value from a python variable
body: <p>I am writing a function that will retrieve data from sqlite table based on the parameters user provide. This is the function so far</p>
  
  <pre><code>def database_retrieve(db_file, id):
      try:
          conn = sqlite3.connect(db_file)
  
          with conn:
              sql_command = "SELECT * FROM my_table WHERE id = "+id
  
              cur = conn.cursor()
              cur.execute(sql_command)
              result = cur.fetchall()
  
              return result
  
      except Exception as e:
          print(e)
  
  db_file = 'testdb.db'
  print(database_retrieve(db_file, 'subject1'))
  </code></pre>
  
  <p>This gives me the following error</p>
  
  <pre><code>no such column: subject1
  None
  </code></pre>
  
  <p>When I add <code>subject1</code>, which is an entry under the <code>id</code> column in <code>my_table</code>, directly to the sql command  like this</p>
  
  <pre><code>sql_command = "SELECT * FROM my_table WHERE id = 'subject1'"
  </code></pre>
  
  <p>it works fine and prints all the data.</p>
  
  <p>I am new to sqlite3. Please help. Thanks in advance</p>
  
  <p>These are the links I used to come this far
  <a href="https://stackoverflow.com/questions/13880786/python-sqlite3-string-variable-in-execute">Python sqlite3 string variable in execute</a></p>
  
  <p><a href="https://www.dummies.com/programming/databases/how-to-retrieve-data-from-specific-rows-in-mysql-databases/" rel="nofollow noreferrer">https://www.dummies.com/programming/databases/how-to-retrieve-data-from-specific-rows-in-mysql-databases/</a></p>