I have an app that uses SQLite to store data locally. There may be more than one file storing the data. All the files contain a list of items, but only one of them has the "correct" status for the current user (basically, there is a "user" db in $HOME and a "system-wide" one in /etc).
Usually, both files will contain the same list of items, and only the status column will differ. If, however, either contains items not in both, I want that data as well.
SQLite does not have FULL OUTER JOIN.
A solution I have come up with is this:
SELECT item, group_concat(status) AS status FROM (SELECT item,status FROM items UNION SELECT item,status FROM otherdb.items) GROUP BY item;
And then parsing the comma-separated "status" output to get the "right" status. I would like a pure SQL solution, however.
The values I want for status are:
If any = 1, status = 1
elif any = -1, status = -1
elif any = 2, status = 2
elif any = -2, status = -2
else status = 0 or NULL
status may only (in the db) be -2,-1,0,NULL,1,2 so this covers all data.
If there is a solution that only gives whichever one is non-zero and non-null, that could work too, although I would prefer the above.