shadowhand/latitude

How to make scalar subquery (query in select)?

Closed this issue · 2 comments

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

These queries would be better served by JOINs, which are available in the query builder. The group_concat can be done with func helper.

And, if you really wanted to, you could use express(...) to build these.