1
I’m developing a Python system and wanted to return data from the specific database, only instead of the foreign key id I wanted to return the name of that person.
The creation of tables:
self.cursor.execute("CREATE TABLE IF NOT EXISTS pessoas(id INTEGER PRIMARY KEY AUTOINCREMENT,nome TEXT, cpf TEXT UNIQUE, tipo TEXT, nascimento DATETIME, telefone TEXT)")
self.cursor.execute("CREATE TABLE IF NOT EXISTS doacoes(id INTEGER PRIMARY KEY AUTOINCREMENT, doador_id INTEGER, litros INTEGER, tipo TEXT, FOREIGN KEY(doador_id) REFERENCES pessoas(id))")
Function that returns the data from the donation table:
def consultar_estoque(self):
estoque = self.cursor.execute("SELECT * from doacoes ORDER BY id DESC")
self.db.commit()
return estoque.fetchall()
As I said above, it returns the id, but wanted the name of the person related to that id. For that I would have to make another query? Or is there an easier way to accomplish the relationship?
Thank you very much!!
– Lucas Gabriel