Fixed error in sql query