Hello everyone, is it possible to do common table ...
# exposed
r
Hello everyone, is it possible to do common table expression like this example with exposed ?
Copy code
WITH ten_parents AS (SELECT * from parent LIMIT 10)
SELECT *
  FROM ten_parents p
    LEFT JOIN child c
      ON c.parent_id = p.id
The goal here is to limit a join request but only for the parents, as they can have several children šŸ™‚
s
I think you should be able to
Copy code
SELECT *
  FROM (SELECT * from parent LIMIT 10) AS p
    LEFT JOIN child c
      ON c.parent_id = p.id
Isnt that enough ?
šŸ‘ 1
r
Yes, it does also the trick šŸ™‚ Is there an easy way with the DSL syntax to do so?
s
Something like
Copy code
tbl.slice(col1).selectAll().limit(10).alias("p")
r
I will try to do that with my own classes, thanks šŸ™‚
I think I succeeded with your syntax. Here is the result with my own tables:
Copy code
val query = (PlaceTable leftJoin PlaceScheduleTable).selectAll()
      .apply { if (count != null) limit(count, offset) }.alias("p")

    val results = query
      .leftJoin(PlaceImageTable, { PlaceImageTable.place }, { query[PlaceTable.id] })
      .leftJoin(FileTable, { FileTable.id }, { PlaceImageTable.file })
      .selectAll()
Thank you again @spand šŸ™‚
s
Excellent šŸ™‚
Though I cant see why you want to leftjoin in
query
when you do it later also
r
That is not the same table, if I do it earlier, I will not have all the images linked to places
šŸ‘ 1