Added SQL for when the id is not defined.