updated sql querying