Sql updated and fixed