I'm performing the following query that joins across 3 tables to pull back workouts and the tags associated with them.
(db/query {:select [:workouts.id :workouts.name :tag.tag_name]
:from [:workouts]
:left-join [[:workout_tags :workout_tag] [:= :workout_tag.workout_id :workouts.id]
[:tags :tag] [:= :tag.tag_id :workout_tag.tag_id]]
:where [:= :workouts.id 1]}))
This returns the following:
({:id 1, :name "Short", :tag_name "cardio"}
{:id 1, :name "Short", :tag_name "No weights"})
Ideally, I'd like to return to the end user a single result with the tag_name
being combined into a single field. Something like:
{:id 1, :name "Short", :tag_name ["cardio" "No weights"]}
It would see that I could fairly easily do this after the fact, but I wanted to see if there's a built in MySQL function that can do what I'm looking to accomplish. It seems maybe GROUP_CONACT
might do what I'm looking for, but I can't seem to get it to work in the context of HoneySQL.
I would do it after the fact:
The intermediate result
grouped
looks likeSee my favorite template project for full config details.