Thanks will check.

Root cause of this kind of complexity is that sqlite doesn't support JOINING on UPDATE:
http://stackoverflow.com/questions/773441/how-do-i-make-an-update-while-joining-tables-on-sqlite