Support Zend_Db_Select sub selects ?

5 messages Options
Embed this post
Permalink
sNop

Support Zend_Db_Select sub selects ?

Reply Threaded More More options
Print post
Permalink
Hi,

something like this:
SELECT `akt`.`n`
FROM (
  SELECT `name` AS `n`
  FROM `aktualne`
) AS `akt`
WHERE `akt`.`n` = '2008'

Support this Zend_Db_Select ?

Thank for any suggestions.



signature.asc (267 bytes) Download Attachment
Hector Virgen

Re: Support Zend_Db_Select sub selects ?

Reply Threaded More More options
Print post
Permalink
You should be able to do that if you wrap your subselect in a Zend_Db_Expr object. Try this:

$subSelect = $db->select()
->from('aktualne', array('n' => 'name'));

$subSelectString = '(' . $subSelect->__toString() . ')';

$select = $db->select()
->from(
    array('akt' => new Zend_Db_Expr($subSelectString)),
    array('n')
)
->where('akt.n = ?', 2008);

$db->fetchAll($select);

--
Hector


2009/9/29 sNop <[hidden email]>
Hi,

something like this:
SELECT `akt`.`n`
FROM (
 SELECT `name` AS `n`
 FROM `aktualne`
) AS `akt`
WHERE `akt`.`n` = '2008'

Support this Zend_Db_Select ?

Thank for any suggestions.


Gina-Marie Rollock

RE: Support Zend_Db_Select sub selects ?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

I do it almost the same way. The only difference to Hector’s solution is that I use the actual select object in the new select statement instead of converting it to a string. This works very well for me.

 

$subSelect = $db->select()

->from('aktualne', array('n' => 'name'));

 

$select = $db->select()

->from(

    array('akt' => $subSelect),

    array('n')

)

->where('akt.n = ?', 2008);

 

Gina-Marie Rollock

 

From: Hector Virgen [mailto:[hidden email]]
Sent: Tuesday, September 29, 2009 12:02 PM
To: sNop
Cc: [hidden email]
Subject: Re: [fw-db] Support Zend_Db_Select sub selects ?

 

You should be able to do that if you wrap your subselect in a Zend_Db_Expr object. Try this:

 

$subSelect = $db->select()

->from('aktualne', array('n' => 'name'));

 

$subSelectString = '(' . $subSelect->__toString() . ')';

 

$select = $db->select()

->from(

    array('akt' => new Zend_Db_Expr($subSelectString)),

    array('n')

)

->where('akt.n = ?', 2008);

 

$db->fetchAll($select);


--
Hector

2009/9/29 sNop <[hidden email]>

Hi,

something like this:
SELECT `akt`.`n`
FROM (
 SELECT `name` AS `n`
 FROM `aktualne`
) AS `akt`
WHERE `akt`.`n` = '2008'

Support this Zend_Db_Select ?

Thank for any suggestions.

 

sNop

Re: Support Zend_Db_Select sub selects ?

Reply Threaded More More options
Print post
Permalink
Great, thank you, this is exactly what i need




signature.asc (267 bytes) Download Attachment
Hector Virgen

Re: Support Zend_Db_Select sub selects ?

Reply Threaded More More options
Print post
Permalink
Cool, I didn't realize you could pass in a select object as the table. Nice! :)

--
Hector


On Tue, Sep 29, 2009 at 11:04 AM, sNop <[hidden email]> wrote:
Great, thank you, this is exactly what i need