db: query construction for all records.