title: Retrieve data using JOIN sql in Zend Framework 2
body: <p>I need to retrive data from 2 tables using join.</p>
  
  <p>I have this code, but it fails with <code>Call to undefined method Zend\Db\ResultSet\ResultSet::from()</code>:</p>
  
  <pre><code>public function getUsers($id){
      $id  = (int) $id;
      $rowset = $this-&gt;tableGateway-&gt;select()-&gt;from(array('u' =&gt; 'user'))
          -&gt;join(array('l' =&gt; 'levels'),
              'u.user_id = l.id_user');
      $row = $rowset-&gt;current();
      if (!$row) {
          throw new \Exception("Could not find row $id");
      }
      return $row;
  }
  </code></pre>
  
  <p>The SQL command would be:</p>
  
  <pre><code>select user.*,levels.name from user left join levels on user.user_id=levels.id_user
  </code></pre>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  Using @Mohamad changes I get:</p>
  
  <pre><code>The table name of the provided select object must match that of the table
  </code></pre>
  
  <p>My UsersTable.php looks like this now:</p>
  
  <pre><code>&lt;?php
  // module/Users/src/Users/Model/UsersTable.php:
  namespace Users\Model;
  
  use Zend\Db\TableGateway\TableGateway;
  use Zend\Db\Sql\Select;
  
  class UsersTable
  {
      protected $tableGateway;
  
      public function __construct(TableGateway $tableGateway)
      {
          $this-&gt;tableGateway = $tableGateway;
      }
  
      public function fetchAll()
      {
          $select = new Select();
          $select-&gt;from('levels');
          $select-&gt;join('user', 'levels.id=user.user_id',Select::SQL_STAR,Select::JOIN_RIGHT);
          $rowset = $this-&gt;tableGateway-&gt;selectWith ( $select );
  
          $resultSet = $rowset-&gt;current();
          if (!$resultSet) {
              throw new \Exception("Could not find row $id");
          }
          return $resultSet;
      }
  </code></pre>