<p>How to query multiple users and join to assets field?</p>
<p>I want to query users with IDs <code>[1,3,4]</code> and <code>inner join</code> it to <code>assets</code> field with <code>volumeId</code> <code>5</code> and <code>title</code>s <code>[1,3,4]</code>.</p>
<p>Tried this but this is probably wrong (returns error):</p>
<pre><code>$res = User::find()
  -&gt;id([ 1, 2, 4 ])
  -&gt;innerJoin('craft_assets assets', 'assets.volumeId=5')
  -&gt;innerJoin('craft_content content, ', &quot;content.title IN (1, 2, 4) &quot;)
  -&gt;createCommand()
  -&gt;queryAll();

Craft::dd($res);
</code></pre>
<p>Any help is appreciated.</p>

CC BY-SA 4.0
2022-08-26T08:55:57.547Z
What is the point you want to inner join with the assets?  what kind of relation you wanted  between the user and the assets?
aodihis
CC BY-SA 4.0
2022-08-26T17:49:11.397Z
@aodihis I want to query users and join the assets with the name of the user IDs (those assets are named after the user IDs.
tenshi
<assets><users><join>
Query multiple users and inner join to assets field
# Query multiple users and inner join to assets field

(Asked by: username_0 on 2022-08-17)

How to query multiple users and join to assets field?
I want to query users with IDs [1,3,4] and inner join it to assets field with volumeId 5 and titles [1,3,4].
Tried this but this is probably wrong (returns error):
$res = User::find()
  ->id([ 1, 2, 4 ])
  ->innerJoin('craft_assets assets', 'assets.volumeId=5')
  ->innerJoin('craft_content content, ', "content.title IN (1, 2, 4) ")
  ->createCommand()
  ->queryAll();

Craft::dd($res);

Any help is appreciated.

**Tags:** assets, users, join
> **Comments:**
> **username_1**: What is the point you want to inner join with the assets?  what kind of relation you wanted  between the user and the assets?  
> **username_0**: @aodihis I want to query users and join the assets with the name of the user IDs (those assets are named after the user IDs.  

---

## 0 answers

