0

Using the SurrealDB select statement, how would one aggregate all the array values from all the records of the 'program' field into a single array with unique values? The answer should look like this:

program: ['flights','apps','entertainment']

Using the following data set with two records:

[
    {
        email: 'jan@test3.co.za',
        firstname: 'Jan',
        id: person:0b3b952c565155fcb0ae9acfedf99315,
        lastname: 'Morkel',
        program: [
            'flights',
            'apps'
        ]
    },
    {
        email: 'sam@test3.co.za',
        firstname: 'Sam',
        id: person:8bc35665018b595b95bd9b2e909ed651,
        lastname: 'pedlar',
        program: [
            'entertainment',
            'flights'
        ]
    }
]
TuinBoy
  • 185
  • 1
  • 9

1 Answers1

-1

If your dataset is called person for instance, you can try the following:

SELECT array::group(program) FROM person GROUP ALL;

See this related GitHub Issue: https://github.com/surrealdb/surrealdb/issues/2133

naisofly
  • 104
  • 1
  • 4
  • This select statement gives the following error: There was a problem with the database: There was an error processing a remote HTTP request I tried: SELECT array::group(program) as program FROM person GROUP program But this then gives { [ program: [ 'flights', 'apps' ] ] }, { [ program: [ 'entertainment', 'flights' ] ] } – TuinBoy Jun 16 '23 at 12:01
  • Please try SELECT array::group(program) FROM person GROUP ALL; as mentioned in the Github Issue linked above. Hope this helps! – naisofly Jul 06 '23 at 13:02