# Query expressions add new with AND and OR

**URL:** <https://discourse.cakephp.org/t/query-expressions-add-new-with-and-and-or/3550>\
**Category:** Uncategorized\
**Created:** [November 21, 2017, 7:40pm UTC](https://discourse.cakephp.org/t/query-expressions-add-new-with-and-and-or/3550 "2017-11-21T19:40:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [November 21, 2017, 7:40pm UTC](https://discourse.cakephp.org/t/query-expressions-add-new-with-and-and-or/3550/1 "2017-11-21T19:40:08Z")

</div>

I try to create and chain expression with different conjunction, but it seems I do not undertood how does it work.

```
$e = new QueryExpression();
$e->add(['OR' => '1=2']);
$e->add($e->and_('3=4'));
$e->add($e->or_('5=6'));
$e->add(['AND' => '7=8']);

```

The result of the abode is `(1=2 AND 3=4 AND 5=6 AND 7=8)`

Ho do I add AND and OR conjunctions?

---

<div class="post-metadata">

**Author:** ![jarekgol](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jarekgol](https://discourse.cakephp.org/u/jarekgol)\
**Post date:** [November 22, 2017, 11:14pm UTC](https://discourse.cakephp.org/t/query-expressions-add-new-with-and-and-or/3550/2 "2017-11-22T23:14:30Z")

</div>

there was orWhere() and andWhere() which I was use  
[https://book.cakephp.org/3.0/en/orm/query-builder.html#advanced-conditions](https://book.cakephp.org/3.0/en/orm/query-builder.html#advanced-conditions)

but there is also info that they are deprecated.

---

<div class="post-metadata">

**Author:** ![raul338](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/raul338/32/69_2.png) [@raul338](https://discourse.cakephp.org/u/raul338)\
**Post date:** [November 25, 2017, 5:14pm UTC](https://discourse.cakephp.org/t/query-expressions-add-new-with-and-and-or/3550/3 "2017-11-25T17:14:46Z")

</div>

The way I found is that you have to create a new QueryExpression for every part of it

```php
$query->newExpr()
    ->eq(1, 2)
    ->add(
        $query->newExpr('3 = 4')
            ->add($query->newExpr()->eq(5, 6))
            ->setConjunction('OR')
    )
    ->add($query->newExpr('7 = 8');

```
