0

Im trying to build a complex (well...) query with Zend_Db_Table where I will both need to join the original table with an extra table and get some extra info from the original table with zend_db_expr.

However, things go wrong from the start. What I to is this:

$select = $this->getDbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
                             ->setIntegrityCheck(false);

$select->from( $this->getDbTable() , array(
    '*' ,
    new Zend_Db_Expr('`end` IS NULL as isnull') ,
    new Zend_Db_Expr('`sold` IN (1,2,3) as issold') ,
) );                                     

Zend_Debug::dump( $select->__toString() );exit;

What results in this:

SELECT `items`.*, `items_2`.*, `end` IS NULL as isnull, `sold` IN (1,2,3) as issold FROM `items`
 INNER JOIN `items` AS `items_2`

What I need it to be though, at this point before I do the join with the other table, is

SELECT `items`.*, `end` IS NULL as isnull, `sold` IN (1,2,3) as issold FROM `items`

I don't need an inner join with itself, I just need to add those two Zend_Db_Expr to the things that should be selected, after which I'd continue building the query with the join and where's etc. like

$select->joinLeft( ... )
->where(...)

Any ideas? Cheers.

1 Answer 1

1

You should not redo a ->from() call, which means yu add a new table in the query. Instead you should just use ->where()->columns() calls containing you Zend_Db_expr.

edit: sorry for the mistake.

Sign up to request clarification or add additional context in comments.

2 Comments

how can I select a Zend_Db_expr via ->where()? To get those expressions I needed out of my query I'll need to define them in the SELECT .... part, which, as far as I can see, is only possible using from, right?
you're right, it's in the select, wait a little i'll edit the response

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.