HomeActive Query Builder - Query analysis and modificationProgrammatic modification of SQL queriesHow to add LIMIT clause to MySQL query

2.10. How to add LIMIT clause to MySQL query

To get access to the LIMIT clause of MySQL Server query, you should use the MySQLSubQuerySelectExpressionExtender object that could be obtained in the following way:

SQLSubQuerySelectExpression selexpr = queryBuilder1.ActiveSubQuery.ActiveUnionSubquery.QueryAST;
MySQLSubQuerySelectExpressionExtender extender = (MySQLSubQuerySelectExpressionExtender) selexpr.Extender;

Use one of the following code samples to add the LIMIT clause programmatically:

// add "LIMIT n" clause
extender.Limit = new SQLLimit(queryBuilder1.SQLContext);
extender.Limit.Limit = 100;

// or add "LIMIT n OFFSET n"
extender.Limit = new SQLLimitOffset(queryBuilder1.SQLContext);
extender.Limit.Limit = 100;
((SQLLimitOffset) extender.Limit).Offset = 20;


This page was: Helpful | Not Helpful