Python SQL syntax

135 views Asked by At

Hey guys using pymysql here.

What is wrong with this syntax?

cursor.execute("SELECT laptopname FROM laptops WHERE laptops.idlaptops NOT IN (SELECT idlaptops FROM bookings WHERE (booked=1) AND (datetime >= %s AND datetime <= %s)", (datetimeout,datetimein))

Thank you!

Edit: The error report: pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1")

Edit 2: Solved but also, how do I make it so my WHERE statement doesn't treat datetime as a column but as a variable/input?

Edit 3: Rápli András's answer was very useful, thanks!!!

1

There are 1 answers

4
Rápli András On BEST ANSWER

datetime is a reserved word in SQL, you can't use that as column name or you have to put it in backticks like this:

`datetime`