0

I have in a dbtable

field 1   field 2
1         2
2         3
2         3
2         2
1         1
2         2

I want to get

field 1 field 2
1       2
2       3
2       2
1       1

Tried

$select = $this->_dbTable->select()->from($this->_dbTable,array("DISTINCT(field_1) as field_1","DISTINCT(field_2) as field_2"));
$select = $this->_dbTable->select()->from($this->_dbTable,array("DISTINCT(field_1, field_2) as field_1, field_2"));

PS: Why this Zend Framework's so hard?!

user1890184
  • 49
  • 2
  • 10

3 Answers3

1

As Sashi Kant suggested this can be done by a group by on field_1, field_2. Here is how to make it using Zend DB :

$select = $this->_dbTable->select()->from($this->_dbTable, array("field_1", "field_2"))
                                   ->group(array("field_1", "field_2"));
Fouad Fodail
  • 2,653
  • 1
  • 16
  • 16
0

Try this :

Select 
field1,
field2
from mytable
group by field1, field2
Sashi Kant
  • 13,277
  • 9
  • 44
  • 71
0

You can use Zend_Db_Expr too

Try this:

$select = $this->_dbTable->select()->from($this->_dbTable, new Zend_Db_Expr('DISTINCT(field_1) as field_1'));
Dapter20
  • 353
  • 4
  • 5