S
S
Sergey Yavin2020-05-20 13:01:45
Python
Sergey Yavin, 2020-05-20 13:01:45

How to find Last_name by id in SQlite database?

There is a table reg_studs with columns id, first_name, last_name, group . You need to know first_name by ID . id_studs - student ID.

The code I wrote doesn't work. Where did I go wrong?

def get_name_student(id_studs):
  conn = get_connection()
  c = conn.cursor()
  c.execute("""
    SELECT reg_studs.id_studs, reg_studs.last_name
    FROM reg_studs
    WHERE (((reg_studs.id)= id_studs));
    """)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-05-20
@sjaserds

You are not formatting the request correctly.
You need it like this:

def get_name_student(id_studs):
  conn = get_connection()
  c = conn.cursor()
  c.execute('SELECT first_name FROM reg_studs WHERE id=?', id_studs)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question