An Overview of Queries in Version 8

Introduction

According to the Family Historian Help file “A query is a reusable set of instructions for extracting information from a Family Historian project. The information returned by a query is called a result set, and it is laid out in tabular form, in a grid of rows and columns.” If the query is an Individual query, each row corresponds to an Individual record; if it is a Source query, each row corresponds to a Source record; and so on for every record type. There are also three types of query that do not return records: Fact queries (one row per event or attribute), Citation queries (one row per source citation) and Witness queries (one row per person in a non-principal role in a shared event).

Queries are a very powerful feature of ƒh because they allow you to analyse your data in almost any way you can think of. What did my direct ancestors die from? How large were the families of the people in my tree? What facts have I entered without citing a source? All these and many more questions can be answered using Queries.

This article is for ƒh Version 8, which rebuilt the Query Window. If you use Version 7 or earlier, see An Overview of Queries in Version 7 and below. Queries written for earlier versions (.fhq files) are converted automatically when you install Version 8 or import them; the Version 8 format is .fhqx.

Standard and Custom Queries

Queries fall into two categories: Standard Queries, which are distributed with ƒh and cannot be edited (except to change the behaviour when printed), and Custom Queries which are created by users (either for personal use or to share via the Queries section of our Downloads page).

Queries are run from the Query button on the main toolbar, whose dropdown lists them by category; the first item opens the Query Window without running anything, and New Custom Query and Manage Queries are on the same menu. Inside the Query Window, the cog menu on the query toolbar has the same commands plus Save As Custom Query, which is the usual way to start from a standard query you want to change.

See The Query Window for instructions on how to use the Query Window and all its tabs. You are advised to read the Help file before moving on to the Hints and Tips below.

What Changed in Version 8

Columns tab: the Fields Etc list with Common Functions
Columns tab: the Fields Etc list with Common Functions

If you know the Version 7 Query Window, these are the differences you will notice:

  • The Rows tab is now the Filters tab, and the four conditions (Add If, Add Unless, Exclude If, Exclude Unless) have gone. Filters are now combined with AND and OR, grouped into subgroups nested as deep as you like, and shown as a tree: AND groups in blue, OR groups in green. Old queries are converted automatically. See Filters below.
  • “Parameter” is now “Prompt” throughout.
  • The Fields list on the Columns tab is now Fields Etc, because it also contains a Common Functions branch (with Counts beneath it) of ready-made function expressions you can add without writing them.
  • Expressions are hidden by default in both the Columns and Filters lists; the cog menu below each list has Show Expressions. Filters can carry a description instead.
  • The Data Reference Assistant is now the Expression Entry Assistant, reached from the Insert button beside any expression field, and helps with functions as well as data references.
  • A Manage Queries tool lists every query with its type, description and last-updated date, filterable by category, type or text, and is where you rename, clone, delete, import and export.
  • Three new query types: Address, Citation and Witness. Several new standard queries.
  • A new column type, Group By, used by Smart Folders (see An Overview of Smart Folders). The Query Window is also where Smart Folders are designed; the button on its own toolbar shows or hides the Smart Folder pane.
  • Drag and drop works in both the Columns and Filters lists (hold Ctrl to copy), and you can drag a field straight from the Fields Etc list into the Columns list.
  • Right-click a record in the Result Set for Record Links, which lists everything that links to it.
  • Queries are stored as .fhqx files.

Filters

Filters tab: AND (blue) and OR (green) groups
Filters tab: AND (blue) and OR (green) groups

Every query has a domain, which is the whole set of records or items of its type, and filters decide which of them appear in the result set. If there are no filters, everything appears. There are four kinds, each with its own tab at the bottom of the Filters tab: General (an expression compared with a value; this is where prompts live, so that the person running the query is asked for a value), Relationships (Individual queries only), List (membership of a Named List; record queries only) and Subgroup.

When you add a filter you are asked how it should combine with the ones already there, AND or OR, and ƒh makes a subgroup if it needs one. Right-click a filter or the background of the list for the cog menu: clone, disable, move into or out of a group, and set whether the top-level group or any subgroup is matched when all its members match (AND) or any of them do (OR). Disabling a filter (or a whole subgroup) is the quickest way to find out which one is producing an unexpected result.

Expression Entry Assistant
Expression Entry Assistant

Two things carried over from the old Rows tab are worth knowing. Relationship filters are still applied in order within their group, so “any of the above” means the filters above it in the same group. And the standard queries’ filters all have descriptions; when you write your own, giving each a description makes the tree readable without expressions.

Working with Query Results

Any entry that is a Record can be double-clicked to open its Property Box to review or edit fields, or right-clicked for Properties and Record Links.

Any entry that is a Data Field can be right-clicked to choose Locate in Property Box or Locate in All Tab. Notes and other long text can be opened with View in Note Window.

Any entry that is a Data Field can have its contents deleted by pressing the DELETE key. Also, by selecting multiple entries such as an entire column, bulk deletes can be applied. Ctrl+A selects the whole result set.

The cog menu also has Run and Invert Result Set (everything the query does not match), and commands to add the row records to a Named List or set a flag on them.

Printing the Results Set from a Query

It is possible to Print the Results Set from a Query, and the General tab of the Query Window has the Title, Subtitle, orientation and multi-page options for the printed output. Title and subtitle accept special codes for the date and time; see Query Window: General Tab.

The Title and custom Subtitle also have an undocumented feature: a value entered at a prompt could be included by writing it as ["Prompt"], where Prompt is the prompt’s label, wrapped in a type function of the matching kind, e.g. Date =Number(["Day"]) of =Text(["Month"]) for =Individual(["Person"]).

Saving Results to a File

The Save Result Set As command on the cog menu saves the whole result set as a PDF, a comma-separated CSV file or a text file. The CSV options offer UNICODE UTF-8 and ANSI encoding, but some spreadsheet programs do not handle UNICODE UTF-8 well, so try both options, or even the Save As Text File options with either Tab character or Comma as the column separators. See also How to Open UTF-8 in Excel.

You should note that Excel (as shipped) does not support dates earlier than 1 January 1900. There are two approaches to dealing with this:

  1. Use numerical columns for Day, Month and Year in your queries if you intend to export them to Excel.
  2. If you’re very comfortable with Excel, explore the techniques in How to Work with Dates Before 1900 in Excel.

Custom Queries

Manage Queries dialog
Manage Queries dialog

You can create your own custom queries — see Searching and Querying Videos for video tutorials on how to do so (made for Version 7, so the Rows tab they show is now the Filters tab). The easiest start is Save As Custom Query on a standard query that does nearly what you want, then edit the copy. When you create one from scratch, leave Add default columns ticked; you get the columns the Records Window uses for that record type and can prune from there.

Or you can download a Custom Query that somebody else has written (for example from the Queries section of our Downloads page or the FHUG forums). If you download a Custom Query, you must install it before you can use it. The simplest way to do so is to double-click on the file to open it; ƒh will automatically install it. Queries written for earlier versions are converted as they are installed.

Custom Query Types

It is important to consider which type of Query will be most useful for the problem you want to solve.

  • Individual queries are the most popular. They return a set of Individual records; the columns can include records linked to an Individual (e.g. Family or Source records, or Individual records for spouses and children). For example, if you want to identify a set of Individuals who meet a set of criteria (e.g. male Individuals who were born between two specified years and still alive in 1914, so might have legally served in World War 1) an Individual query is what you need. However, to show more than a few selected Facts in the Result Set will require a Column for every field of each and every type of Fact plus each and every instance of multiple Facts such as Census. That could run to dozens if not hundreds of Columns. If your focus is on the Facts for a set of Individuals, consider a Fact Query instead.
  • A Fact Query focuses on Facts, not records, but the Columns and Filters can refer to any items, including records associated with a Fact. For example it can include, each in a different Column, the Individual or Family record that owns the Fact, or any Source records cited by the Fact. However, each Row in the Result Set is keyed to just one unique Fact, and that Fact is only represented on one Row. So, if you want to view all the Education Facts for people in your family tree, a Fact query is what you want.
  • A Citation Query returns one row per source citation, with the source, the record and fact cited, and Where within Source available as columns. It is the natural way to find everything cited to a source, or every citation with a particular assessment.
  • A Witness Query returns one row for each person in a non-principal role in a shared event: every bridesmaid, every godparent, every beneficiary of a will. Someone who witnessed the same event twice gets two rows.
  • Family queries will return a list of Family records that meet your chosen criteria. So, if you want to see a list of couples who married between two dates in a particular place, a Family query is what you want.
  • You can also construct Queries based on Address, Media, Note, Place, Repository, Research Note and Source Template records. For example, you can query to see all the Sources you consulted at a particular Repository, or every Address linked to a given Place.

Columns Tab Advice

In the Columns Tab:

  • Data Reference Fields are chosen using the Fields Etc pane on the left. Click on any + sign to expand a sub-list, and having selected a Field, click on the Add Column > button (or double-click it, or drag it across). This will add a Heading and an Expression to the Columns pane on the right. Although these Columns are listed vertically, they will appear horizontally in the Result Set, and moving them up and down actually moves them left and right in the results.
  • The Common Functions branch of the same list holds ready-made expressions such as ages, counts of spouses or children, and Address and Place; select one and read its description in the box below before adding it. For an introduction to writing your own see Understanding Data References and Understanding Functions. If you have created Text Schemes in Diagrams, these Expressions are almost identical.
  • Remember that many Data Reference Fields can have more than one instance, but only the first one is added by default. For example the Individual > Name field has an Expression of %INDI.NAME[1]%. If any Individual has Alternate Names then %INDI.NAME[2]% and %INDI.NAME[3]% will also exist, and these must be entered as extra Columns and the index adjusted to [2] or [3] by hand (turn on Show Expressions from the cog menu to see them). It is easily overlooked that Attributes, Events, Sources, and many other fields often have multiple instances that need to be incorporated.
  • Column types are Normal, Hidden, Buddy and Group By. Hidden columns sort without showing; a Buddy column data-links the column before it so that double-clicking opens the record; Group By is for Smart Folders and behaves as Hidden in an ordinary query.

Sorting a Fact Query on Owner Surname

In a Fact Query the Owner of the Fact is displayed using one of these Column Expressions:

  • =FactOwner(%FACT%,1,MALES_FIRST) for Family Fact Husband or Individual Fact Owner.
  • =FactOwner(%FACT%,2,MALES_FIRST) for Family Fact Wife (otherwise blank).
  • =GetRecord(%FACT%) for Family Fact Husband & Wife record or Individual Fact Owner record.

They all display the name of the owner with forenames first and surname last, so it is not possible to sort them in surname order. The following column expressions allow you to obtain surname sort order:

  • =FieldText(FactOwner(%FACT%,1,MALES_FIRST),'INDI.NAME:SURNAME_FIRST') which displays the surname first, and sorts in surname order, but is NOT an active link to the Individual record.
  • =Field(FactOwner(%FACT%,1,MALES_FIRST),'INDI.NAME') which still displays forenames first, but sorts in surname order, and is an active link to the Individual record.

Those two Expressions can be combined into one Result Set Column that exhibits the best features of both:

  • 1st Column uses Expression: =FieldText(…) with Sort: None and Type: Normal so appears in Result Set.
  • 2nd Column uses Expression: =Field(…) with Sort: Ascending and Type: Buddy so is hidden, but defines the sort order of 1st Column and provides an active link.
Last update: 2026-10-16 07:06:22