2

I just want to return one column (per.cd_acao), so I tried something like:

$select->from(array('act' => 'tb_acao'))
           ->join(array('per' => 'tb_perfil_acao'),
                'per.cd_acao = act.cd_acao',
                array('cd_acao'),
                $select::JOIN_INNER
            );

but this is producing a query string like: SELECT "act".*, "per"."cd_acao" AS "cd_acao" FROM "tb_acao" AS "act" INNER JOIN "tb_perfil_acao" AS "per" ON "per"."cd_acao" = "act"."cd_acao" WHERE "per"."sq_perfil" = '89'

it is bringing all columns from the first table, when I want none. What am I missing here?

Update

summarizing: When I don't inform 'columns' in a select object, it defaults to return all columns to me. But when I'm joining, I don't want any columns to be returned by the first table.

2 Answers 2

4

An empty array will suffice

$select->from(array('act' => 'tb_acao'))
           ->columns(array())
           ->join(array('per' => 'tb_perfil_acao'),
                'per.cd_acao = act.cd_acao',
                array('cd_acao'),
                $select::JOIN_INNER
            );
Sign up to request clarification or add additional context in comments.

Comments

0

Try with this query

use Zend\Db\Sql\Sql;

protected $tableGateway;
public $adapter;

public function __construct(TableGateway $tableGateway)
{
    $this->tableGateway = $tableGateway;
}

publice function getData(){
    $adapter = $this->tableGateway->getAdapter();
    $sql = new Sql($adapter);
    $select = $sql->select();
    $select->from('tb_acao')
       ->join('per'),
            'per.cd_acao = act.cd_acao',
            array('cd_acao'),
        );
    $statement = $sql->prepareStatementForSqlObject($select);
    $results = $statement->execute();

    return $results;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.