# Query concatination in GORM

**URL:** <https://forum.golangbridge.org/t/query-concatination-in-gorm/4348>\
**Category:** Getting Help\
**Created:** [January 12, 2017, 5:24am UTC](https://forum.golangbridge.org/t/query-concatination-in-gorm/4348 "2017-01-12T05:24:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nirmal\_Singh](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@Nirmal\_Singh](https://forum.golangbridge.org/u/Nirmal_Singh)\
**Post date:** [January 12, 2017, 5:24am UTC](https://forum.golangbridge.org/t/query-concatination-in-gorm/4348/1 "2017-01-12T05:24:01Z")

</div>

Can anyone tell me how to append where conditions in Gorm query according to the parameters conditions?

---

<div class="post-metadata">

**Author:** ![ragona](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/ragona/32/2679_2.png) [@ragona](https://forum.golangbridge.org/u/ragona)\
**Post date:** [January 12, 2017, 8:39pm UTC](https://forum.golangbridge.org/t/query-concatination-in-gorm/4348/2 "2017-01-12T20:39:42Z")

</div>

The [docs](http://jinzhu.me/gorm/crud.html#query) note that you can chain queries like this:

```
db.Where("name <> ?","jinzhu").Where("age >= ? and role <> ?",20,"admin").Find(&users)

```

Is that what you’re looking for? Alternately you could conditionally construct structs to pass to the query:

```
func query(name, age) {
  var user *User
  if someCondition {
    user = &User{name: name, age: age}
  } else {
    user = &User{name: name} 
  db.Where(user).First(&user)
}
```

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [April 12, 2017, 8:39pm UTC](https://forum.golangbridge.org/t/query-concatination-in-gorm/4348/3 "2017-04-12T20:39:49Z")

</div>

Closed on April 12, 2017, 8:39pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
