SELECT tnrs.* , tnrs_accepted."Time_submitted" AS "Accepted_name.Time_submitted" , tnrs_accepted."Name_number" AS "Accepted_name.Name_number" , tnrs_accepted."Name_submitted" AS "Accepted_name.Name_submitted" , tnrs_accepted."Overall_score" AS "Accepted_name.Overall_score" , tnrs_accepted."Name_matched" AS "Accepted_name.Name_matched" , tnrs_accepted."Name_matched_rank" AS "Accepted_name.Name_matched_rank" , tnrs_accepted."Name_score" AS "Accepted_name.Name_score" , tnrs_accepted."Name_matched_author" AS "Accepted_name.Name_matched_author" , tnrs_accepted."Name_matched_url" AS "Accepted_name.Name_matched_url" , tnrs_accepted."Author_matched" AS "Accepted_name.Author_matched" , tnrs_accepted."Author_score" AS "Accepted_name.Author_score" , tnrs_accepted."Family_matched" AS "Accepted_name.Family_matched" , tnrs_accepted."Family_score" AS "Accepted_name.Family_score" , tnrs_accepted."Name_matched_accepted_family" AS "Accepted_name.Name_matched_accepted_family" , tnrs_accepted."Genus_matched" AS "Accepted_name.Genus_matched" , tnrs_accepted."Genus_score" AS "Accepted_name.Genus_score" , tnrs_accepted."Specific_epithet_matched" AS "Accepted_name.Specific_epithet_matched" , tnrs_accepted."Specific_epithet_score" AS "Accepted_name.Specific_epithet_score" , tnrs_accepted."Infraspecific_rank" AS "Accepted_name.Infraspecific_rank" , tnrs_accepted."Infraspecific_epithet_matched" AS "Accepted_name.Infraspecific_epithet_matched" , tnrs_accepted."Infraspecific_epithet_score" AS "Accepted_name.Infraspecific_epithet_score" , tnrs_accepted."Infraspecific_rank_2" AS "Accepted_name.Infraspecific_rank_2" , tnrs_accepted."Infraspecific_epithet_2_matched" AS "Accepted_name.Infraspecific_epithet_2_matched" , tnrs_accepted."Infraspecific_epithet_2_score" AS "Accepted_name.Infraspecific_epithet_2_score" , tnrs_accepted."Annotations" AS "Accepted_name.Annotations" , tnrs_accepted."Unmatched_terms" AS "Accepted_name.Unmatched_terms" , tnrs_accepted."Taxonomic_status" AS "Accepted_name.Taxonomic_status" , tnrs_accepted."Accepted_name" AS "Accepted_name.Accepted_name" , tnrs_accepted."Accepted_name_author" AS "Accepted_name.Accepted_name_author" , tnrs_accepted."Accepted_name_rank" AS "Accepted_name.Accepted_name_rank" , tnrs_accepted."Accepted_name_url" AS "Accepted_name.Accepted_name_url" , tnrs_accepted."Accepted_name_species" AS "Accepted_name.Accepted_name_species" , tnrs_accepted."Accepted_name_family" AS "Accepted_name.Accepted_name_family" , tnrs_accepted."Selected" AS "Accepted_name.Selected" , tnrs_accepted."Source" AS "Accepted_name.Source" , tnrs_accepted."Warnings" AS "Accepted_name.Warnings" , tnrs_accepted."Accepted_name_lsid" AS "Accepted_name.Accepted_name_lsid" FROM tnrs LEFT JOIN tnrs tnrs_accepted ON tnrs_accepted."Name_submitted" = NULLIF(array_to_string(ARRAY[ NULLIF(tnrs."Accepted_name_family", 'Unknown') , tnrs."Accepted_name" , tnrs."Accepted_name_author" ], ' '), '') ORDER BY "Name_submitted" ; ALTER TABLE :table ADD PRIMARY KEY ("Name_submitted");