Get unique ids before querying database