# Self-join in action objects

**URL:** <https://community.developer.atlassian.com/t/self-join-in-action-objects/78979>\
**Category:** Jira Server\
**Tags:** active-objects\
**Created:** [April 8, 2024, 2:07pm UTC](https://community.developer.atlassian.com/t/self-join-in-action-objects/78979 "2024-04-08T14:07:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![esselllesse](https://avatars.discourse-cdn.com/v4/letter/e/50afbb/32.png) [@esselllesse](https://community.developer.atlassian.com/u/esselllesse)\
**Post date:** [April 8, 2024, 2:07pm UTC](https://community.developer.atlassian.com/t/self-join-in-action-objects/78979/1 "2024-04-08T14:07:59Z")

</div>

Hello!

i have a query:

```auto
SELECT t2.email 
FROM myTable t1
JOIN myTable t2 ON t1.parentId = t2.id
WHERE t1.email = 'myemail'

```

how to implement it using AO?  
(ao.find(MyClass.class, Query.select…etc))

i tried to make two aliases for same table and join it to itself, but it does not work

it looks like

```auto
String email = "myemail";
ao.find(
            MyClass.class,
            Query.select()
                .alias(MyClass.class, "entity1")
                .alias(MyClass.class, "entity2")
                .join(MyClass.class, "entity1.parentId = entity2.id")
                .where("EMAIL = ?", email));

```
