You can translate the question and the replies:

LIMIT not working in a subquery .

I'm trying to execute the following query : ``` SELECT * FROM (SELECT * FROM Connections LIMIT 1000) AS T LIMIT 1; ``` But its giving the following error : Exception parsing query near 'LIMIT' . Can someone help ? OR suggest any alternative working way of writing the above query.
user
18-04-2022 05:17:06 -0400
code

3 Answers

Hi, The error “**Exception parsing query near ‘limit”’** will occur when the syntax of the query is not proper or it may not be delegated to Virtual DataPort. In Denodo,at this moment Limit is only supported at the end of a SELECT statement to reduce the size of the result set but it cannot be used in subqueries. As a workaround to Limit the queries you can create the temporary tables.For instance you can refer the below format: **Syntax:** CREATE TEMPORARY temporary_table_for_subquery AS <subquery> LIMIT x; SELECT * FROM ... temporary_table_for_subquery ... **For your Scenario :** CREATE TEMPORARY temporary_table_for_subquery AS SELECT * FROM Connections LIMIT 1000; SELECT * FROM ... temporary_table_for_subquery ...limit 1 For more information , you could take a look at the [“OFFSET, FETCH and LIMIT](https://community.denodo.com/docs/html/browse/latest/en/vdp/vql/queries_select_statement/offset_fetch_and_limit/offset_fetch_and_limit#offset-fetch-and-limit)” section under the Virtual DataPort VQL Guide. Hope this helps!
Denodo Team
19-04-2022 06:13:12 -0400
code
Hi, Thank you for the response. Wanted to know can you provide a workaround without CREATE sql. Our usecase only supports SELECT statements. If there are any alternatives with only using SELECT statements, then please suggest.
user
25-04-2022 02:12:04 -0400
Hi, I would suggest you to use the below **SELECT** query in order to use **LIMIT** clause, **Query :** ``` SELECT * FROM ( SELECT *, rownum() from <view_name>) WHERE rownum <=1000 limit 1 ``` For more information, you can take a look at the “[ROWNUM](https://community.denodo.com/docs/html/browse/8.0/en/vdp/vql/functions/other_functions/other_functions#rownum)” section under Virtual DataPort VQL Guide. Hope this helps !
Denodo Team
25-04-2022 06:21:35 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here