title: Python MYSQL - insert distinct values
body: <p>I have a database table with a simple id and name columns, and a csv file with some dummy names where some of them are duplicates. I'm trying to read only the unique values.</p>
  
  <pre><code>def readCsv(fileName):
  #open connection
  reader = csv.DictReader(open(fileName, encoding="utf8"))
  connection = pyodbc.connect(
      'DRIVER=' + DRIVER + ';PORT=1433;SERVER=' + SERVER + ';PORT=1433;DATABASE=' + DATABASE + ';UID=' + USERNAME + ';PWD=' + PASSWORD)
  cursor = connection.cursor()
  
  #Reading of the file
  counter = 0
  #Iterate line by line
  for line in reader:
      insertSql = "INSERT INTO Dummy VALUES(?)"
      result = cursor.execute(insertSql,
                              line['name'])
      cursor.commit()
      counter+= 1
  </code></pre>
  
  <p>This correctly inputs all the names in the database, but I have duplicate names that I don't want. 
  I've tried using INSERT IGNORE, but that somehow returns an error that INTO isn't correct?</p>
  
  <pre><code>insertSql = "INSERT IGNORE INTO Dummy VALUES(?)"
  </code></pre>
  
  <blockquote>
    <p>pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near the keyword 'INTO'. (156) (SQLExecDirectW)")</p>
  </blockquote>
  
  <p>I've had a similar result with using  ON DUPLICATE, where it just says now ON isn't valid.</p>
  
  <pre><code>insertSql = "INSERT INTO Dummy VALUES(?) ON DUPLICATE KEY UPDATE name=name"
  </code></pre>
  
  <blockquote>
    <p>pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near the keyword 'ON'. (156) (SQLExecDirectW)")</p>
  </blockquote>
  
  <p>Ive thought that one of those should work, but I don't know what I'm doing wrong here?</p>