# Subquery examples

**URL:** <https://forum.datomic.com/t/subquery-examples/345>\
**Category:** Datomic Pro\
**Created:** [February 22, 2018, 3:44pm UTC](https://forum.datomic.com/t/subquery-examples/345 "2018-02-22T15:44:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustingetz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.datomic.com/dustingetz/32/56_2.png) [@dustingetz](https://forum.datomic.com/u/dustingetz)\
**Post date:** [February 22, 2018, 3:44pm UTC](https://forum.datomic.com/t/subquery-examples/345/1 "2018-02-22T15:44:44Z")

</div>

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

```auto
(->> $
     (d/q
       '[:find ?name ?c :in $ :where
         [?e :community/name ?name]
         [?e :community/category ?c ?maxtx]
         [(datomic.api/q
            '[:find (max ?tx) . :where
              [_ :community/category _ ?tx]]
            $)
          ?maxtx]]))
=> #{["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"] ...

```
