Question

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?

Was it helpful?

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

OTHER TIPS

Use WHERE X=Y AND Y=Z not WHERE X=Y, Y=Z

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

You are using commas in the WHERE clause and you should use AND's.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top