How to make scalar subquery (query in select)?
Closed this issue · 2 comments
usefksa commented
Thanks for the great library.
Is it possible to build a scalar subquery ( query in select ) without using join?
I want to build these MySQL queries:
- simple
SELECT posts.id, ( select tagName FROM tags WHERE postTags.postId = posts.id ) AS postTags
FROM posts WHERE id=1
- complex
SELECT posts.id, ( select GROUP_CONCAT(tagName SEPARATOR "^") FROM tags WHERE postTags.postId = posts.id ) AS postTags
FROM posts WHERE id=1
shadowhand commented
These queries would be better served by JOINs, which are available in the query builder. The group_concat
can be done with func helper.
shadowhand commented
And, if you really wanted to, you could use express(...)
to build these.