Alright, so basically, i have a table structured like this
| ActorID | Name | Surname | Birthdate | Website |
|---|
(with some data in it, of course)
And i want to select an actor depending on what their last name starts with.
So i know the SQL Request should be
SELECT ActorID FROM Actors WHERE Name LIKE '{Letter}%'
However, i want to do it with sqlite3 in python, and when i write it this way:
cur.execute("""
SELECT name, surname FROM acteurs WHERE name LIKE '?%';
""",firstletter)
actors = cur.fetchall()
I get a syntax error "sqlite3.OperationalError: near ";": syntax error"
How should i modify it to make it work ?
Thanks in advance
>Solution :
The ? placeholder must not be inside the single quotes.
The % wildcard must be concatenated to the ? placeholder.
Also, you must pass firstletter as a member of a tuple:
cur.execute("SELECT name, surname FROM acteurs WHERE name LIKE ? || '%'", (firstletter,))