1

I was using the SELECT method in a function. I tried to Select all the rows where "First_Name," a column, is equal to "FirstName," a variable. However, it gives me an error saying that "FirstName" is not a column. I have no idea how to fix this issue. I have copy-pasted the SELECT statement below.

c.execute('SELECT * FROM AccountLists WHERE First_Name = FirstName AND Last_Name = LastName')
Andrej Kesely
196k15 gold badges60 silver badges105 bronze badges
asked Jul 19, 2018 at 17:24

1 Answer 1

1

You need use ? notation, like this:

c.execute('SELECT * FROM AccountLists WHERE First_Name=? AND Last_Name=?', (FirstName, LastName))

The ? is a placeholder that you use wherever you want to use a value and then provide a tuple of values as the second argument to the cursor’s execute() method.

answered Jul 19, 2018 at 17:32
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for this information. However, I have found another problem. I used the exact same code but removed the last name portion so the statement looks like: c.execute('SELECT * FROM AccountLists WHERE First_Name=?', (FirstName))
@AnshKumar You forgot put "," after FirstName - to create a tuple: c.execute('SELECT * FROM AccountLists WHERE First_Name=?', (FirstName, ))

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.