title: Yii2: Is it possible 2 databases query at once with JOIN?
body: <p>I have project on Yii2. I have 2 databases. I need to execute command with <code>join</code> like</p>
  
  <pre><code>SELECT * FROM `table1` LEFT JOIN `table2` ON `table1`.`id` = `table2`.`id`;
  </code></pre>
  
  <p>..where <code>table1</code> is from <code>db1</code> and <code>table2</code> from <code>db2</code>. notice: <code>db2</code> is on another server.</p>
  
  <pre><code>        'db1' =&gt; [
              'class' =&gt; 'yii\db\Connection',
              'dsn' =&gt; 'mysql:host=localhost;dbname=db1',
              'username' =&gt; '...',
              'password' =&gt; '...',
              'charset' =&gt; 'utf8',
          ],
          'db2' =&gt; [
              'class' =&gt; 'yii\db\Connection',
              'dsn' =&gt; 'mysql:host=anotherserver.com;dbname=db2',
              'username' =&gt; '...',
              'password' =&gt; '...',
              'charset' =&gt; 'utf8',
          ]
  </code></pre>
  
  <p><strong>Q1:</strong> How to do that on clean mysql/php? on Yii2?
  .. or the only way is to fetch results from <code>table1</code> and <code>table2</code> separated and then loop to compare <code>id</code>?</p>
  
  <p><strong>Q2:</strong> How to compare <code>id</code> in yii2 in <code>dataProvider</code>?</p>
  
  <pre><code>$query = Table1::find();
  $query2 = Table2::find();
  // how compare id?
  
  $dataProvider = new ActiveDataProvider([
      'query' =&gt; $query,
  ]);
  </code></pre>