diff --git a/src/content/doc-surrealql/statements/select.mdx b/src/content/doc-surrealql/statements/select.mdx index 58da796fa..2cda0d14d 100644 --- a/src/content/doc-surrealql/statements/select.mdx +++ b/src/content/doc-surrealql/statements/select.mdx @@ -200,8 +200,13 @@ More info on the `$parent` parameter in the second example can be seen on [the p ```surql -- Store the subquery result in a variable and query that result. -LET $history = SELECT * FROM events WHERE type = 'activity' LIMIT 5; -SELECT * from $history; +LET $avg_price = ( + SELECT math::mean(price) AS avg_price FROM product GROUP ALL + ).avg_price; + +-- Find the name of the product where the price is higher than the avg price +SELECT name from product +WHERE [price] > $avg_price; -- Use the parent instance's field in a subquery (predefined variable) SELECT *, (SELECT * FROM events WHERE host == $parent.id) AS hosted_events FROM user;