doublevas
9 months ago

How to express subQuery with MIN() without raw SQL?

Posted 9 months ago by doublevas

There are container and weights related as one-to-many. Is it possible to translate this query to Query Builder chain without raw SQL:

SELECT c.*, w.weight
FROM containers AS c
JOIN weights AS w ON w.id = (
    SELECT MIN(id) 
    FROM weights 
    WHERE container_id = c.id
)

Thank you in advance.

Please sign in or create an account to participate in this conversation.