Answer the question
In order to leave comments, you need to log in
How to delete multiple rows of SQLite data in Python?
And so, I need to delete one row of data in the sqlite table, but I can’t figure out how to do it. And so the table has the following data.
I need to delete this row
. On the Internet, the deletion example is everywhere.
But this command will delete all rows where Finance is present in the department_name column. But I need to do this:
id = 674759776
If id_1 == with my id
Then delete the data line where my id is present. That is the following line
How can this be done?
Answer the question
In order to leave comments, you need to log in
In short, I solved the problem in the following way:
import sqlite3
conn = sqlite3.connect("local.db", check_same_thread = False) # или :memory: чтобы сохранить в RAM
cursor = conn.cursor()
my_id = 74654758345
cursor.execute('SELECT id_2 FROM stol_game WHERE id_1 = ?', (my_id, ))
id_2_turtle = cursor.fetchone()
id_2 = int(id_2_turtle[0])
cursor.execute('SELECT brosokone2 FROM stol_game WHERE id_1 = ?', (my_id, ))
brosokone2turtle = cursor.fetchone()
brosokone2 = int(brosokone2turtle[0])
cursor.execute('SELECT brosoktwo2 FROM stol_game WHERE id_1 = ?', (my_id, ))
brosoktwo2turtle = cursor.fetchone()
brosoktwo2 = int(brosoktwo2turtle[0])
cursor.execute('SELECT vsumme2 FROM stol_game WHERE id_1 = ?', (my_id, ))
vsumme2turtle = cursor.fetchone()
vsumme2 = int(vsumme2turtle[0])
cursor.execute('SELECT stavka2 FROM stol_game WHERE id_1 = ?', (my_id, ))
stavka2turtle = cursor.fetchone()
stavka2 = int(stavka2turtle[0])
cursor.execute('SELECT frend_id FROM stol_game WHERE id_1 = ?', (my_id, ))
frend_id2turtle = cursor.fetchone()
frend_id = int(frend_id2turtle[0])
cursor.execute('SELECT brosokone1 FROM stol_game WHERE id_1 = ?', (my_id, ))
brosokone1turtle = cursor.fetchone()
brosokone1 = int(brosokone1turtle[0])
cursor.execute('SELECT brosoktwo1 FROM stol_game WHERE id_1 = ?', (my_id, ))
brosoktwo1turtle = cursor.fetchone()
brosoktwo1 = int(brosoktwo1turtle[0])
cursor.execute('SELECT vsumme1 FROM stol_game WHERE id_1 = ?', (my_id, ))
vsumme1turtle = cursor.fetchone()
vsumme1 = int(vsumme1turtle[0])
cursor.execute('SELECT stavka1 FROM stol_game WHERE id_1 = ?', (my_id, ))
stavka1turtle = cursor.fetchone()
stavka1 = int(stavka1turtle[0])
cursor.execute('SELECT win FROM stol_game WHERE id_1 = ?', (my_id, ))
win2turtle = cursor.fetchone()
win = int(win2turtle[0])
cursor.execute('DELETE FROM stol_game WHERE id_1 = ? AND frend_id = ? AND brosokone1 = ? AND brosoktwo1 = ? AND vsumme1 = ? AND stavka1 = ? AND id_2 = ? AND brosokone2 = ? AND brosoktwo2 = ? AND vsumme2 = ? AND stavka2 = ? AND win = ?', (my_id, frend_id, brosokone1, brosoktwo1, vsumme1, stavka1, id_2, brosokone2, brosoktwo2, vsumme2, stavka2, win, ))
conn.commit()
Have you tried adding another condition to the database query?
The rows have different id_1 and id_2
Or you can use TOP, LIMIT, ROWNUM
If you are sure that the first line in the database is exactly what you need and you should delete it, then feel free to use what I described in the line above
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question