Skip to content

Comments

add support for subqueries in select expression#616

Open
sasa-b wants to merge 2 commits intokotlin-orm:masterfrom
sasa-b:master
Open

add support for subqueries in select expression#616
sasa-b wants to merge 2 commits intokotlin-orm:masterfrom
sasa-b:master

Conversation

@sasa-b
Copy link

@sasa-b sasa-b commented Feb 22, 2026

This is a common use case when we want to have a column derived from a subquery, most often it is a correlated subquery https://dev.mysql.com/doc/refman/8.4/en/correlated-subqueries.html.

SELECT 
departments.id,
depratments.name,
(SELECT COUNT(*) FROM employees WHERE employees.department_id = departments.id) AS total_employess 
FROM departments;

P.S. If there is interest, I can raise a follow-up PR to add support for subqueries in where statements.

This is kinda already supported with the InListExpression and ExistsExpression, but that only covers two use cases, we could add support for all the other operators like >, <, =, >=, <= etc. It's fairly common to have aggregate subqueries in where conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant