# Subquery Inner Join

**URL:** <https://discourse.rom-rb.org/t/subquery-inner-join/542>\
**Category:** Issues\
**Created:** [July 14, 2022, 3:49pm UTC](https://discourse.rom-rb.org/t/subquery-inner-join/542 "2022-07-14T15:49:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![neroy](https://avatars.discourse-cdn.com/v4/letter/n/87869e/32.png) [@neroy](https://discourse.rom-rb.org/u/neroy)\
**Post date:** [July 14, 2022, 3:49pm UTC](https://discourse.rom-rb.org/t/subquery-inner-join/542/1 "2022-07-14T15:49:52Z")

</div>

I have a question. How can I write a query like this in rom:

```auto
SELECT COUNT(*)
FROM "table_a"
INNER JOIN (
  SELECT "column_x"
  FROM "table_b"
  WHERE "table_b"."column_y" = '<whatever>' ORDER BY "table_b"."column_y" asc limit 1) 
) AS "some_alias" ON "table_b"."column_x" = "table_a"."id"
WHERE "table_a"."column_a" = 1;

```

I am more interested in the inner join’s nested subquery though. I can only pass a relation to the .left\_join and I can’t seem to be able to figure this out with blocks or any other way with the builtin methods. I tried views as well but they do not apply. Am I missing something? Can I somehow pass a dataset or a literal?
