Updated SQL to reflect latest changes