|
Post by baroquedub on May 25, 2023 11:52:32 GMT
I'm trying to delete entries in three tables linked together using a common key: Sessions.id (see: baroquedub.co.uk/private/forum-images/linked-tables.png ) I tried this: // Delete from Therapies any id that matches therapy_id FK in Sessions
DBSingleton.Instance.dbManager.Execute("DELETE FROM Therapies WHERE id IN (SELECT t.id FROM Therapies t INNER JOIN Sessions s ON t.id = s.therapy_id WHERE s.id = ?", DBSingleton.Instance.currentSessionId);
// delete PatientSessions that have session_id FK as currentSessionId
DBSingleton.Instance.dbManager.Execute("DELETE FROM PatientSessions WHERE session_id = ?", DBSingleton.Instance.currentSessionId);
// delete Sessions that have id currentSessionId
DBSingleton.Instance.dbManager.Execute("DELETE FROM Sessions WHERE id = ?", DBSingleton.Instance.currentSessionId); but I'm getting an error on the first query: SQLiteException: incomplete input I'm not that familiar with SQL queries, can anyone help me work out where I'm going wrong? (I used OpenAi to help write that join statement...) Attachments:
|
|
|
Post by baroquedub on May 25, 2023 11:57:35 GMT
Nevermind, worked it out!
For anyone interested, there was a typo on my query (missing closing bracket). Should have been:
DBSingleton.Instance.dbManager.Execute("DELETE FROM Therapies WHERE id IN (SELECT t.id FROM Therapies t INNER JOIN Sessions s ON t.id = s.therapy_id WHERE s.id = ?)", DBSingleton.Instance.currentSessionId);
|
|
|
Post by echo17 on May 26, 2023 11:25:55 GMT
Nice! Thanks for sharing your solution.
|
|