How to merge two queries into one?

Hello, can you tell me how can i merge that two queries in one ?

    ids = from(relationship in UserProject,
              where: relationship.user_id == ^,
              join: p in Project, where: relationship.project_id ==,
|> Repo.all

query = from(p in Project,
            where: ( in ^ids),
            where: ilike(, ^"%#{substring}%")

Can add one more join maybe?

|> where([p], ilike(, ^"%#{substring}%"))
|> join(:inner, [p], up in UserProject, == up.project_id)
|> where([p, up], up.user_id == ^
|> select([p, up], p)
|> Repo.all()

Or just remove Repo.all() to get a query.

Here is variant where you get query in the end still

user_projects_query =
        relationship in UserProject,
        join: p in Project,
        on: relationship.project_id ==,
        where: relationship.user_id == ^,
        where: ilike(, ^"%#{substring}%"),
        select: p