I would like to know how I can use a subquery in FROM clause using gorm. It would look like the following:
SELECT * FROM
(
SELECT foo.*
FROM foo
WHERE bar
Solved this issue by creating a package for more flexibility: https://github.com/loeffel-io/sql
subquery := sql.Create().
Select(true, "purchases.*").
Select(true, "...").
From(true, "purchases").
Join(true, "transactions ON transactions.purchase_id=purchases.id")
query := sql.Create().Select(true, "*").
From(true, "(?) purchases", gorm.Expr(subquery.GetSQL(), subquery.GetValues()...)).
Join(true, "transactions ON transactions.id=purchases.last_transaction_id")
db.
Raw(query.GetSQL(), query.GetValues()...).
Offset(...).
Limit(...).
Order(...).
Unscoped().
Find(&purchases).
Error