5

結合には「id」という名前のフィールドも含まれているため、最初に選択したテーブルの id フィールド名を上書きしないように、SQL 中にこのフィールド名を変更する必要があります。

私のクエリは次のようになります。

$select = new \Zend\Db\Sql\Select();
$select->from('websites');
$select->join(array('s' => 'websites_statistics'), 's.website_id = websites.id');
$select->where(array('websites.website' => $website));
$select->order('s.timestamp DESC')->limit(1);

$rowset = $this->tableGateway->selectWith($select);
$row = $rowset->current();

return $row;

したがって、「s」「id」フィールドは「stat_id」のような名前に変更する必要があります。

前もって感謝します!

ニック

4

3 に答える 3

10
$select = new \Zend\Db\Sql\Select();
$select->from('websites');
       ->join(array('s' => 'websites_statistics'), 's.website_id = websites.id',
           array('stat_id' => 's.id')); // <-- here is the alias
       ->where(array('websites.website' => $website));
       ->order('s.timestamp DESC')
       ->limit(1);
于 2013-01-07T12:02:34.830 に答える