Subquery examples


I have been thinking a lot about Datomic Subqueries which are a d/q inside a d/q and thinking about interesting things that they make possible, anyone have good examples of using this? The example I found on the google group is:

For a :many, find the most recent addition

(->> $
       '[:find ?name ?c :in $ :where
         [?e :community/name ?name]
         [?e :community/category ?c ?maxtx]
            '[:find (max ?tx) . :where
              [_ :community/category _ ?tx]]
=> #{["KOMO Communities - South Lake Union" "criminal activity"] ["Beach Drive Blog" "news"] ["KOMO Communities - View Ridge" "events"] ["Fremont Chamber of Commerce" "chamber of commerce"] ["KOMO Communities - Rainier Valley" "shopping"] ...