FAIMS-452 - fix queries for database selection