{"id":11110,"date":"2020-08-05T14:14:10","date_gmt":"2020-08-05T14:14:10","guid":{"rendered":"https:\/\/fhug.org.uk\/kb\/?post_type=kb_article&#038;p=11110"},"modified":"2024-02-24T15:21:51","modified_gmt":"2024-02-24T15:21:51","slug":"an-overview-of-queries","status":"publish","type":"kb_article","link":"https:\/\/www.fhug.org.uk\/kb\/kb-article\/an-overview-of-queries\/","title":{"rendered":"An Overview of Queries"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>According to the Family Historian Help file &#8220;A <span class=\"definition\">query<\/span> is a reusable set of instructions for extracting information from a Family Historian file. The information returned by a query is called a <em><span class=\"definition\">Result Set<\/span><\/em>, and it is laid out in tabular form, in a grid of rows and columns. Each row in the Result Set corresponds to a record. If the query is an <span class=\"definition\">Individual<\/span> query, each row returned will correspond to an Individual record. If it is a <span class=\"definition\">Source<\/span> query, each row will correspond to a Source record.&#8221;<\/p>\n<p>There are more types of queries, of course: you can create a query based on any Record Type that <span class=\"fh\" style=\"font-size: 17px !important; line-height: 21.4286px !important;\">\u0192<span style=\"color:#73B262; font-weight: bold;\">h<\/span><\/span> support, and also on Facts.<\/p>\n<p>Queries are a very powerful feature of <span class=\"fh\" style=\"font-size: 17px !important; line-height: 21.4286px !important;\">\u0192<span style=\"color:#73B262; font-weight: bold;\">h<\/span><\/span> because they allow you to analyse your data in an almost any way you can think if. 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.<\/p>\n<h2>Standard and Custom Queries<\/h2>\n<p>Queries fall into two categories: Standard Queries, which are distributed with <span class=\"fh\" style=\"font-size: 17px !important; line-height: 21.4286px !important;\">\u0192<span style=\"color:#73B262; font-weight: bold;\">h<\/span><\/span> 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 <a href=\"https:\/\/fhug.org.uk\/kb\/download-type\/query\/\">the Queries section of our Downloads page<\/a>).<\/p>\n<p>Queries are accessed via the Query Window (<a href=\"#!\" class=\"cs_tooltip\" fhugtt=\"This is the menu across the top of the main Family Historian windows. The &gt; denotes a submenu\">View&nbsp&gt;&nbspMore&nbspWorkspace&nbspWindows&nbsp&gt;&nbspQuery&nbspWindow<\/a>) or the Query Window icon <img decoding=\"async\" class=\"cs_v alignnone lazyload\" data-src=\"https:\/\/fhug.org.uk\/kb\/wp-content\/uploads\/2020\/helpv6\/querywindow_2.png\" alt=\"\" width=\"36\" height=\"31\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 36px; --smush-placeholder-aspect-ratio: 36\/31;\" \/> in the main toolbar. If you want to navigate straight to a Standard query, use <a href=\"#!\" class=\"cs_tooltip\" fhugtt=\"This is the menu across the top of the main Family Historian windows. The &gt; denotes a submenu\">View&gt;&nbspStandard&nbspQueries&nbsp&gt;&nbsp<em>Query&nbspname<\/em><\/a>; and if you want to navigate straight to a Custom Query, use <a href=\"#!\" class=\"cs_tooltip\" fhugtt=\"This is the menu across the top of the main Family Historian windows. The &gt; denotes a submenu\">View&gt;&nbspCustom&nbspQueries&nbsp&gt;&nbsp<em>Query&nbspname<\/em><\/a>\n<p>See <a href=\"https:\/\/www.family-historian.co.uk\/help\/fh6\/hh_start.htm#querywindow.html\" target=\"_blank\" rel=\"noopener noreferrer\">The Query Window<\/a> 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.<\/p>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Working with Query Results<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>Any entry that is a Record can be double-clicked to open its Property Box to review or edit fields.<\/p>\n<p>Any entry that is a Data Field can be right-clicked to choose Locate in Property Box or Locate in All Tab.<\/p>\n<p>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, then bulk deletes can be applied.<\/p>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Printing the Results Set from a Query<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>It is possible to <em>Print the Results Set<\/em> from a Query, and there are <em>Print Detail<\/em> options to configure the printed output on the <em>General<\/em> tab of the Query Window.<\/p>\n<p>Most of the Print Details options are self-explanatory, but the <em>Title<\/em> and <em>Subtitle Custom<\/em> options have some undocumented features to incorporate any Value entered via a <em>Rows Tab<\/em> prompt for a <em>Parameter<\/em>. Any such Value is represented by <code>[\u201cPrompt\u201d]<\/code>, where Prompt is the name of the parameter Label, and to include it in the Title or Subtitle it must be enclosed in a Type Specifier Function of a matching type: <code>Text([\u201cPrompt\u201d]), Number([\u201cPrompt\u201d]), Individual([\u201cPrompt\u201d]), Date([\u201cPrompt\u201d])<\/code>, etc.<br \/>\ne.g. <code>Date =Number([\"Day\"]) of =Text([\"Month\"]) for =Individual([\"Person\"])<\/code><\/p>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Saving Results to a File<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>Since <span class=\"fh\" style=\"font-size: 17px !important; line-height: 21.4286px !important;\">\u0192<span style=\"color:#73B262; font-weight: bold;\">h<\/span><\/span> V6 the Save Results to File menu <img decoding=\"async\" class=\"cs_v alignnone lazyload\" data-src=\"https:\/\/fhug.org.uk\/kb\/wp-content\/uploads\/2020\/helpv6\/toolbar_query_8.png\" alt=\"\" width=\"40\" height=\"31\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 40px; --smush-placeholder-aspect-ratio: 40\/31;\" \/> offers two <em>Save As Comma-Separated CSV File<\/em> options for 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 <a href=\"https:\/\/smallbusiness.chron.com\/open-utf8-excel-63726.html\">How to Open UTF-8 in Excel 2013-2016<\/a> and <a href=\"https:\/\/www.itg.ias.edu\/content\/how-import-csv-file-uses-utf-8-character-encoding-0\">How to Import CSV file that uses UTF-8 in Excel 2007<\/a>.<\/p>\n<p>You should note that Excel (as shipped) does not support Dates earlier than 1 January 1900.\u00a0 There are two approaches to dealing with this:<\/p>\n<ol>\n<li>Use numerical columns for Day Month and Year in your queries if you intend to export them to Excel.<\/li>\n<li>If you&#8217;re very comfortable with Excel, explore the techniques in <a href=\"http:\/\/www.exceluser.com\/formulas\/earlydates.htm\">How to Work with Dates Before 1900 in Excel<\/a><\/li>\n<\/ol>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Custom Queries<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>You can create your own custom queries &#8212; see <a href=\"https:\/\/www.fhug.org.uk\/kb\/videos\/?tx_topic=searching-and-querying\">Searching and Querying Videos<\/a> for video tutorials on how to do so.<\/p>\n<p>Or you can download a Custom Query that somebody else has written (for example from <a href=\"https:\/\/fhug.org.uk\/kb\/download-type\/query\/\">the Queries section of our Downloads page <\/a>or the <a href=\"https:\/\/fhug.org.uk\/forum\/index.php\">FHUG forums).<\/a> 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; <span class=\"fh\" style=\"font-size: 17px !important; line-height: 21.4286px !important;\">\u0192<span style=\"color:#73B262; font-weight: bold;\">h<\/span><\/span> will automatically install it.<\/p>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Custom Query Types<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>It is important to consider which type of Query will be most useful for the problem you want to solve.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Individual queries are the most popular. They return a set of Individual records; the columns can include records linked to an Individual (e.g.<glwrap> 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 or thousands of Columns.If your focus is on the Facts for a set of Individuals, consider a Fact Query instead.<\/glwrap><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>A Fact Query focuses on Facts, not records, but the Columns and Rows 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.<\/li>\n<li>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.<\/li>\n<li>You can also construct Queries based on Media, Note, Place and Repository records.For example, you can query to see all the Sources you consulted at a particular Repository.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Columns Tab Advice<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>In the Columns Tab:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Data Reference Fields are chosen using the Fields pane on the left. Click on any + sign to expand a sub-list, and having selected a Field, click on the Add Field as Column button &gt; at the bottom. 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.<\/li>\n<li>If you have created Text Schemes in Diagrams, then these Expressions are almost identical, and similarly can include Functions.Look at other Queries and you will see how they use Fields and Query Functions. For an Introduction to Data References and Functions see <a href=\"https:\/\/fhug.org.uk\/kb\/kb-article\/understanding-data-references\/\">Understanding Data References<\/a> and <a href=\"https:\/\/fhug.org.uk\/kb\/kb-article\/understanding-functions\/\">Understanding Functions<\/a>.<\/li>\n<li>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 &gt; Name field has an Expression of %INDI.NAME[1]%. If any Individual has Alternate Names then <code>%INDI.NAME[2]%<\/code> and <code>%INDI.NAME[3]%<\/code> will also exist, and these must be entered as extra Columns and the index adjusted to [2] or [3] by hand.It is easily overlooked that Attributes, Events, Sources, and many other fields often have multiple instances that need to be incorporated.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/div><\/details><\/div>\n<div class=\"lightweight-accordion\"><details><summary class=\"lightweight-accordion-title\"><h2>Sorting a Fact Query on Owner Surname<\/h2><\/summary><div class=\"lightweight-accordion-body\"><p>In a\u00a0Fact Query\u00a0the\u00a0Owner\u00a0of the\u00a0Fact\u00a0is displayed using one of these\u00a0Column Expressions:<\/p>\n<ul>\n<li><code>=FactOwner(%FACT%,1,MALES_FIRST)<\/code> for Family Fact Husband or Individual Fact Owner.<\/li>\n<li><code>=FactOwner(%FACT%,2,MALES_FIRST)<\/code> for Family Fact Wife (otherwise blank).<\/li>\n<li><code>=GetRecord(%FACT%)<\/code>\u00a0for Family Fact Husband &amp; Wife record or Individual Fact Owner record.<\/li>\n<\/ul>\n<p>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.<\/p>\n<p>These Column Expressions work in FH V5 and above:<\/p>\n<ul>\n<li><code>=FieldText(FactOwner(%FACT%,1,MALES_FIRST),'INDI.NAME:SURNAME_FIRST')<\/code> which displays the surname first, and sorts in surname order, but is NOT an active link to the Individual record.<\/li>\n<li><code>=Field(FactOwner(%FACT%,1,MALES_FIRST),'INDI.NAME')<\/code>\u00a0which still displays forenames first, but sorts in surname order, and is an active link to the Individual record.<\/li>\n<\/ul>\n<p>For\u00a0FH\u00a0V6\u00a0and above, those two\u00a0Expressions\u00a0can be combined into one\u00a0Result Set Column\u00a0that exhibits the best features of both:<\/p>\n<ul>\n<li>1st Column uses\u00a0Expression: =FieldText(\u2026)\u00a0with\u00a0Sort: None\u00a0and\u00a0Type: Normal\u00a0so appears in Result Set.<\/li>\n<li>2nd Column uses Expression: =Field(\u2026) with Sort: Ascending and Type: Buddy so is hidden, but defines the sort order of 1st Column and provides an active link.<\/li>\n<\/ul>\n<\/div><\/details><\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","fh_version":[13,14,15,739],"skill_level":[17,16],"topic":[63],"class_list":["post-11110","kb_article","type-kb_article","status-publish","hentry","fh_version-v4","fh_version-v5","fh_version-v6","fh_version-v7","skill_level-intermediate","skill_level-newcomer","topic-searching-and-querying"],"_links":{"self":[{"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/kb_article\/11110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/kb_article"}],"about":[{"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/types\/kb_article"}],"wp:attachment":[{"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/media?parent=11110"}],"wp:term":[{"taxonomy":"fh_version","embeddable":true,"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/fh_version?post=11110"},{"taxonomy":"skill_level","embeddable":true,"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/skill_level?post=11110"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.fhug.org.uk\/kb\/wp-json\/wp\/v2\/topic?post=11110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}