Search code examples
pythonsqlselectsqliteoperationalerror

What is wrong with this? (sqlite3)


recordCheck = c.execute("SELECT * FROM Student, Behaviour WHERE Forename=:oldForename, Surname=:oldSurname,     YearGroup=:oldYearGroup, FormNumber=:oldFormNumber, Date=:oldDate, BehaviourType=:oldBehaviourType", {"oldForename":oldForename,    "oldSurname":oldSurname, "oldYearGroup":oldYearGroup, "oldFormNumber":oldFormNumber,"oldDate":oldDate,"oldBehaviourType":oldBehaviourType})

This returns this error:

OperationalError: near ",": syntax error

But I can't see what is wrong with it. Can anyone help?


Solution

  • Comma is not valid in a where clause. Conditions are normally separated by AND or OR. So, this is invalid:

    WHERE Forename=:oldForename, Surname=:oldSurname
    

    One of these would be valid:

    WHERE Forename=:oldForename AND Surname=:oldSurname
    
    WHERE Forename=:oldForename OR Surname=:oldSurname