More efficient querying database