updated database query