Search database and filter records with SQL