updated sql query