0

I have a problem with a query like this:

$sSqlAux = $this->select()->setIntegrityCheck(false)
  ->from(array("a_aux" => $this->_name), "id_a", $this->_schema)
  ->join(array("b_aux"=> "b"), "a_aux.id_a = b_aux.id_b", array(), $this->_schema)
  ->join(array("c_aux"=> "c"), "a_aux.id_inscrito = c_aux.id_c", array(), $this->_schema)
  ->where("b_aux.id_b = ?", $this->idB)
;
$sSql = $this->select()->setIntegrityCheck(false)
  ->from(array("a" => $this->_name), "a.id_a, a.campo_a", $this->_schema)
  ->joinLeft(array("b" => "b"), "a.id_a = b.id_b", "b.campo_b", $this->_schema)
  ->joinLeft(array("c" => "c"), "b.id_b = c.id_c", "c.campo", $this->_schema)
  ->where("c.campo_c = ?", "string")
  ->where("a.id_a IN (?)", new Zend_Db_Expr($sSqlAux))
  ->order("c.campo_c")
;

and to return the data, an asterisk is added before the name of the table, in this case, in one of my left joins, table b (LEFT JOIN schema.*b ON a.id_a = b.id_b) like the following example

SELECT 
  a.id_a, 
  a.campo_a 
  b.campo_b, 
  c.campo_c
FROM schema.a a
 LEFT JOIN schema.*b ON a.id_a = b.id_b
 LEFT JOIN schema.c c ON a.id_a = c.id_c
WHERE (c.campo_c = 'string') 
AND (a.id_a IN (
  SELECT a_aux.id_a
  FROM schema.a a_aux 
  INNER JOIN schema.b b_aux ON a_aux.id_a = b_aux.id_b
  INNER JOIN schema.c c_aux ON a_aux.id_a = c_aux.id_c 
  WHERE (a_aux.id_segundo_id = 5321))) 
  ORDER BY c.campo ASC 
)

These are just examples of the problem I'm having, if error in logic or syntax error was in my typing. The real problem is that asterisk added by zend before the table name in the join.

If someone has understood the problem and have a solution that you can share would be of great help.

I'm using zend 1

thank's!

  • you shouldn't need $this->_schema – Rufinus Jul 11 '13 at 14:18
  • thanks for the reply, I tested removing $ this-> _schema as you said, but the error continues, the asterisk changes of place, in this case, go to the last joint "INNER JOIN *c c_aux ON a_aux.id_a = c_aux.id_c" – Fabricio Nogueira Jul 11 '13 at 14:24
  • This is just a wild guess... From what I get, the Zend_Db does not add the " AS ". Maybe due to the fact that the array key is the same as the array value. Try ->joinLeft("b", "a.id_a = b.id_b", "b.campo_b") – Joel Lord Jul 11 '13 at 14:43

1 Answers1

-1

I had the same problem and solved it. I was on an ORACLE Database and all my table names and columns names must be in capital. So try B_AUX instead of b_aux if you're on ORACLE DB too.