Let’s say I have this table:
Parent ID FileName Flag
0 1 C:\ -1
1 2 C:\Test\ 0
2 3 C:\Test\Test2\ 0
3 4 C:\Test\Test2\file.txt 0
0 5 D:\ 0
5 6 D:\file-2.txt 0
I’d like to select records that satisfy these 2 conditions:
- Flag <> -1
- None of the parent records have Flag <> -1
Is this possible in sqlite3? ie.
SELECT FileName FROM MyTable WHERE Flag <> -1 And Recursive(Parent) <> -1
So that in the example table, a query like this would return D:\file-2.txt, but not C:\Test\Test2\file.txt
SQLite does not have any mechanism that could do recursive lookups over arbitrary depths.
You would have to implement this logic in whatever language you are accessing the database from.
In this particular example, you could try to look up based on the file name: