I uncovered a need to perform a nested query recently, but didn't know how to do it using Doctrine DBAL. So, now that I've figured it out, I've blogged about it.
I don't like the following sentence:
> When creating a SELECT using DBAL, you do something like this: $dbal->createQueryBuilder();
DBAL does not force you to use the queryBuilder.
You can just execute the SQL Query as is using fetchAllAssociative.
The queryBuilder is overused for non-dynamic queries in my opinion.
@bcremer The example in my blog post is partial, and doesn't tell the complete story - it's actually built dynamically based on a variety of parameters passed to the method, and some joins, columns, and group statements may be omitted or included as a result. I simplified it for the blog to zero in on the subquery.
@mwop Fair Enough. The QueryBuilder has it's use-cases. But in your blog post it reads like it's the only way to solve this.
@bcremer I've updated the post to clarify this.
To be honest, I often use heredoc SQL strings. Usually when I do that, however, I'll use straight PDO instead of introducing the DBAL; to me, the value of the DBAL is the query builder for dynamically generating queries.