Using a subquery in 'FROM' in gorm

后端 未结 6 1463
梦谈多话
梦谈多话 2021-02-10 03:03

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         


        
6条回答
  •  忘掉有多难
    2021-02-10 03:41

    Also you can do it with join on a subquery

    subQuery := db.
        Select("foo.*").
        Table("foo").
        Where("bar = ?", "baz").
        SubQuery()
    
    db.
        Select("t1.*").
        Join("INNER JOIN ? AS t1 ON t1.id = foo.id", subQuery).
        Where("t1.id = ?", 1)
    

提交回复
热议问题