N1QL - select from subquery


I’m trying to select from sub-query. is it possible?
the idea is so to something like:

SELECT field, count(*) FROM (SELECT DISTINCT .... <my sub-query>) GROUP BY field

I read over this forum that support has been added for this, but It doesn’t seem to work. for a simple test, I tried the following:

SELECT * FROM (SELECT "test" as fake FROM default)
but received:
“code”: 3000,
“msg”: “syntax error - at end of input”,
“query_from_user”: “select * from\n(SELECT “test” as fake\nFROM default)”

am I doing it wrong?

Note: I were able to insert the query result into a different document (by doing INSERT INTO ... SELECT ..), and then query it. but I prefer to avoid this and do it in one shot if possible.

Thanks, Liran

Try this one:

(SELECT "test" as fake
FROM default) a

It works. thanks.

If there are Couchbase members here, I suggest to update the docs with example

1 Like