I have two tables in a SQLITE DB (Table 1 and Table 2). I need to determine which items in table 1 are not in table two, and then print the results. I think I may have a working prototype, but am not familiar with SQL too much.
import sqlite3
sqlite_file = 'data.db'
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
c.execute("SELECT PK FROM Table1 WHERE NOT EXISTS(SELECT 1 FROM Table2 WHERE PK = Table1.pk)")
results = list(c)
count = len(results)
print(results)
print(count)
- Can someone confirm that this looks right?
- Is there a better way to do this? If not, any help would be much appreciated