I'm trying to translate the following SQL to Esqueleto:
SELECT id, task_id, author_id
FROM scenario
INNER JOIN ( SELECT task_id as tId, author_id as aId, MAX(last_update) as lastUp
FROM scenario
GROUP BY task_id, author_id
) t
ON task_id = tId AND author_id = aId AND last_update = lastUp
To do a sub-query, you have to use subList_select.
I couldn't figure out a way to combine it with the pattern matching in:
from $ \(s `InnerJoin` ?subQueryhere?) -> do ...
So I tried with where_
instead:
where_ (s ^. ScenarioTaskId ==. (subList_select $
from $ \s' -> do
groupBy (s' ^. ScenarioTaskId, s' ^. ScenarioAuthorId)
return s'
) ^. ScenarioTaskId)
However, this doesn't compile since subList_select
returns a expr (ValueList a)
instead of a expr (Entity Scenario)
.