%META:TOPICPARENT{name="VirtTipsAndTricksGuide"}% ---++What is the difference between the functions SAMPLE, GROUP_CONCAT and GROUP_DIGEST? This example demonstrates the differences between the functions [[http://docs.openlinksw.com/virtuoso/fn_SAMPLE.html][SAMPLE]], [[http://docs.openlinksw.com/virtuoso/fn_GROUP_CONCAT.html][GROUP_CONCAT]] and [[http://docs.openlinksw.com/virtuoso/fn_GROUP_DIGEST.html][GROUP_DIGEST]]. Assume the following query that should get all ?assets as a list with delimiters: SPARQL SELECT ?view ?path (sql:GROUP_CONCAT (?asset, ' ')) as ?asset_list FROM WHERE { ?view ?path ; ?asset ; 'phyview'. } ; This method is not universal, because conversion to strings will eliminate the difference between strings and IRIs and there should be some delimiter that never appears in values of ?asset. In addition, the query may fail with "row too long" error if values of ?asset are lengthy and/or numerous enough. It is also possible the query not work completely free from duplicates if more than one list is desired. E.g.: SPARQL SELECT ?view (sql:GROUP_CONCAT (?path, ' ')) as ?path_list (sql:GROUP_CONCAT (?asset, ' ')) as ?asset_list FROM WHERE { ?view ?path ; ?asset ; 'phyview' . } will not contain duplicates in lists only if either ?path or ?asset is unique for every found ?view; but if it's so unique then there's no need in the corresponding sql:[[http://docs.openlinksw.com/virtuoso/fn_GROUP_CONCAT.html][GROUP_CONCAT]]() . If there are many values per property but it's enough to return any single value and ignore the rest then use sql:[[http://docs.openlinksw.com/virtuoso/fn_SAMPLE.html][SAMPLE]]() function instead of sql:[[http://docs.openlinksw.com/virtuoso/fn_GROUP_CONCAT.html][GROUP_CONCAT]]() . If there are many values per property and it's better to show more than one value but "row too long" error happens, then the sql:[[http://docs.openlinksw.com/virtuoso/fn_GROUP_DIGEST.html][GROUP_DIGEST]] function can be used: SPARQL SELECT ?view (sql:GROUP_DIGEST (?path, ' ', 1000, 1)) as ?path_list (sql:GROUP_DIGEST (?asset, ' ', 1000, 1)) as ?asset_list FROM WHERE { ?view ?path ; ?asset ; 'phyview' . } ---++Related * [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]] * [[http://docs.openlinksw.com/virtuoso/fn_SAMPLE.html][SAMPLE]] * [[http://docs.openlinksw.com/virtuoso/fn_GROUP_CONCAT.html][GROUP_CONCAT]] * [[http://docs.openlinksw.com/virtuoso/fn_GROUP_DIGEST.html][GROUP_DIGEST]]