Hello, What you're trying to do is currently not possible through the jOOQ API, as jOOQ doesn't expose the SelectQuery's underlying state. Changing these APIs to expose more internal state is on the roadmap: https://github.com/jOOQ/jOOQ/issues/1492
Some comments about your attempts: * Convert query to string > * Create a new query from the string (basically create a copy) > * Call query.getSelect().add(Factory.count()) --> seems to have no effect > This doesn't work, as getSelect() returns a copy of the underlying state > * Create a copy as above > * Call query.getQuery().addSelect(Factory.count()) > * While this does work with an empty select() call it does not work with > select(<fields>) as the existing items cannot be removed > This doesn't work as you're modifying the underlying state "for good" Right now, I see these options for you - none of which are really very nice: - Use reflection to access the SelectQuery's underlying state - Patch jOOQ and expose some internals - Re-create the same SelectQuery twice, once per query Another, better option is to use Factory.countOver() - the COUNT(*) OVER() window function - along with your regular query if your database supports window functions. This would prevent the round trip of executing two queries Cheers Lukas
