0

I have query:

$sql = new Sql($this->tableGateway->getAdapter());
$select = $sql->select();

$select->from('table_1')
    ->join('table_2', 'table_2_se_id = table_2.se_id 
                       and table_2_table_3_id = table_2.table_3_id',
                      '*', 'LEFT')
    ->join('table_3', 'table_2_table_3_id=table_3.id', '*', 'LEFT')
    ->join('table_4', 'table_4_id=table_4.id', '*', 'LEFT');

How to get only one column (for example 'name') from table_4?

Nips
  • 13,162
  • 23
  • 65
  • 103

1 Answers1

2

The third parameter to join() is where you specify columns, at the moment you're selecting all *. The parameter can be a string representing a single column, or an array of columns, so the following should work

->join('table_4', 'table_4_id=table_4.id', 'name', 'LEFT');
Crisp
  • 11,417
  • 3
  • 38
  • 41
  • 2
    Try replacing `'*'` with `array()` in the `joins` you don't want to select columns from – Crisp Mar 10 '13 at 10:15