1

Re: INDEX_TAXON_GROUP sanity check

I've just been working with the INDEX_TAXON_GROUP table and was hoping someone could give me a sanity check on the following.

Here's broadly what I am attempting to do:

Given a taxon name (e.g., 'Chiroptera') I want a list of all taxon_list_item_keys that are descendants of that 'parent' taxon no matter what list they reside on. So if you take my example of Chiroptera, I would want a list of all of the taxon_list_item_keys for all bats in the system regardless of what list those bat species are found on.

The INDEX_TAXON_GROUP table is used for traversing the taxonomic hierarchy: for any given taxon_list_item_key it lists every other taxon_list_item_key both above and below it in the hierarchy.

But things get tricky because some taxa do not have a parent taxon, or they have an irregular hierarchy. In the case of bats, for instance, there are several that reside on the "Red Data Book Vertegrates: Ireland"; these bats have a direct parent of "Mammals (Mammalia)". That being the case, a direct query on INDEX_TAXON_GROUP against the taxon_list_item_key for Chiroptera will not find these bats because they do not have Chiroptera as an ancestor.

So, to solve this - that is, to find every bat on every list, even if it isn't under a 'Chiroptera' parent - I need to find all bats beneath Chiroptera on the preferred list, then, for each of those taxa, I need to look for taxa that join to them via recommended_taxon_list_item_key; i.e., I need to look for all of the non-preferred names for each and every bat taxon.

Clear as mud? Told you I needed a sanity check. ;)

Here's the query I wrote:

select distinct
    itn1.recommended_taxon_list_item_key
    ,itn1.preferred_name
    ,itn2.taxon_list_item_key
    ,itn2.common_name
    ,itn2.preferred_name
    ,itn2.sort_order
from
    index_taxon_group itg
inner join
    index_taxon_name itn1 on
    itg.contained_list_item_key = itn1.taxon_list_item_key
inner join
    index_taxon_name itn2 on
    itn1.taxon_list_item_key = itn2.recommended_taxon_list_item_key
where
    itg.taxon_list_item_key = ( select top 1 itn1.recommended_taxon_list_item_key
                                from index_taxon_name itn1
                                where itn1.preferred_name = 'chiroptera' )
order by
    itn2.sort_order

Can anyone confirm that it does what I think it is supposed to?

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

2

Re: INDEX_TAXON_GROUP sanity check

Charles,

Ya's a brave lad.

M

Cumbria Biodiversity Data Centre
Tullie House Museum

3

Re: INDEX_TAXON_GROUP sanity check

Courage is being scared to death - but saddling up anyway.
--John Wayne

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

4

Re: INDEX_TAXON_GROUP sanity check

Hi Charles,

I tried to think of a witty retort but no joy...

You are on the right lines, but your selection of the top level Chiroptera item to use based on it's preferred name will bring back an arbitrary item to generate the branch from, so not quite! I'd also avoid using a subquery where possible for performance reasons though I think the optimiser is pretty good at handling this sort of thing these days. Here is my effort:

SELECT DISTINCT ITN3.Taxon_List_Item_Key, ITN3.Actual_Name
FROM Index_Taxon_Name ITN
INNER JOIN Index_Taxon_Group ITG ON ITG.Taxon_List_Item_Key=ITN.Taxon_List_Item_Key
INNER JOIN Index_Taxon_Name ITN2 ON ITN2.Taxon_List_Item_Key=ITG.Contained_List_Item_Key
INNER JOIN Index_Taxon_Name ITN3 ON ITN3.Recommended_Taxon_List_Item_Key=ITN2.Recommended_Taxon_List_Item_Key
WHERE ITN.Actual_Name='Chiroptera' AND ITN.Recommended_Taxon_List_Item_Key=ITN.Taxon_List_Item_Key

To explain it, I first find the Chiroptera which "recommends itself" - which should mean it is on the preferred list. Then I find all children of this entry. Then I use 2 instances of the Index_Taxon_Name table to allow a join on Recommended_Taxon_List_Item_Key, which pulls in all the synonyms and names on other lists for each child. That leaves you with the data you want in the table aliased ITN3.

Let me know if this doesn't make sense

Cheers

John van Breda
Biodiverse IT