I have a query which gets a list of notes created for an item . Each item also stores the user guid of the user who created item. The query looks like this, when i use the history.created_by_name i get the below error
[{ “code”: 3000,
“msg”: “syntax error - at .”,
“query”: “SELECT META().id AS DocId,\n subject,\n notes,\n history,\n (\n SELECT RAW name.fname || ’ '|| name.lname AS name\n FROM Contacts USE KEYS ‘user::’ || c.history.created_by)[0] AS history.created_by_name\nFROM Contacts c\nWHERE _type = "notes"\n AND parent_id = ‘farm::CC4816D2-88CB-4C9F-A2D9-34537A1BCFE0’” } ]
SELECT META().id AS DocId,
subject,
notes,
history,
(
SELECT RAW name.fname || ' '|| name.lname AS name
FROM Contacts USE KEYS 'user::' || c.history.created_by)[0] AS created_by_name
FROM Contacts c
WHERE _type = "notes"
AND parent_id = 'farm::CC4816D2-88CB-4C9F-A2D9-34537A1BCFE0'
And the output looks like thsi
[
{
"DocId": "notes::06a6be1d-fcdf-4552-9ad8-11ec23f6e173",
"created_by_name": "Demo User"
],
"history": {
"created_by": "8D6D24A5-D669-45DC-99AC-F257BDA133A4",
"created_on": "2021-08-30T17:21:18.015Z"
},
"notes": "This is some test Notes",
"subject": "Test note"
}
]
what I would like to be able to is move the “created_by_name” key under the history. How can i do this ?