Fix sql queries to retrieve last_modified time