Answers for "gorm order by"

1

gorm order by

db.Order("age desc, name").Find(&users)
// SELECT * FROM users ORDER BY age desc, name;
// Multiple 
ordersdb.Order("age desc").Order("name").Find(&users)
// SELECT * FROM users ORDER BY age desc, name;
db.Clauses(clause.OrderBy{  Expression: clause.Expr{SQL: "FIELD(id,?)", Vars: []interface{}{[]int{1, 2, 3}}, WithoutParentheses: true},}).Find(&User{})
// SELECT * FROM users ORDER BY FIELD(id,1,2,3)
Posted by: Guest on November-16-2020

Browse Popular Code Answers by Language