Use db->getColumn() instead of loops