DEVIDM-106: Restructured & corrected some queries.

Added sub selects for status inserts instead of making assumptions about the db data.