<p>My question is this, <strong>I want to join a matrix table to a query and look for certain values in it</strong>.  I am using this example below.  I have 2 matrix fields partsModels.model and partsModels.parts. I need to make sure that all the criteria is met before looping through any of the data.</p>

<p><code>{% set entries = craft.entries.andWhere(['like', 'content.fields_myFieldHandle', 'foo']).all() %}</code></p>

<p>that Robin supplied <a href="https://craftcms.stackexchange.com/questions/26152/craft-query-matrix-blocks-in-twig/26153?noredirect=1#comment34376_26153">here</a>.</p>

CC BY-SA 4.0
2018-05-16T00:46:28.190Z
I cannot find any documentation on Craft's site on how to structure or code such a query.  Has anyone done this before or used the andWhere on Matrix fields?
Vin
CC BY-SA 4.0
2018-05-17T21:14:17.997Z
Seems like it be easier to just use `search`? It'll ultimately get translated to a `like` on the backend in most cases anyway. `{% set entries = craft.matrixBlocks.search('*foo*').all() %}`
Brad Bell
CC BY-SA 4.0
2018-05-17T21:31:31.250Z
Thanks Brad.  Since that searches through all instances of foo, it will capture things I don't want in the output.  Plus I have two Matrix fields I need to compare before displaying the results.  Like here https://craftcms.stackexchange.com/questions/26183/match-matrix-fields-before-looping-through-results
Vin
<matrix><craft3>
Join Matrix Fields To Query Using andWhere
# Join Matrix Fields To Query Using andWhere

(Asked by: username_0 on 2018-05-15)

My question is this, **I want to join a matrix table to a query and look for certain values in it**. I am using this example below. I have 2 matrix fields partsModels.model and partsModels.parts. I need to make sure that all the criteria is met before looping through any of the data.

`{% set entries = craft.entries.andWhere(['like', 'content.fields_myFieldHandle', 'foo']).all() %}`

that Robin supplied [here](https://craftcms.stackexchange.com/questions/26152/craft-query-matrix-blocks-in-twig/26153?noredirect=1#comment34376_26153).

**Tags:** matrix, craft3

> **Comments:**
> **username_0**: I cannot find any documentation on Craft's site on how to structure or code such a query.  Has anyone done this before or used the andWhere on Matrix fields?  
> **username_1**: Seems like it be easier to just use `search`? It'll ultimately get translated to a `like` on the backend in most cases anyway. `{% set entries = craft.matrixBlocks.search('*foo*').all() %}`  
> **username_0**: Thanks Brad.  Since that searches through all instances of foo, it will capture things I don't want in the output.  Plus I have two Matrix fields I need to compare before displaying the results.  Like here https://craftcms.stackexchange.com/questions/26183/match-matrix-fields-before-looping-through-results  

---

## 0 answers

