Optimized the GET_LAST_EXECUTION query

The query runs a lot faster as it does not have to generate the cartesian product for all of the table