0

i'm a new user of Zend Framework, and i have a problem with the Zend syntax for make this query:

SELECT i.*, k.id as id_key, GROUP_CONCAT(DISTINCT k.nome ORDER BY k.id SEPARATOR " ") as tag, GROUP_CONCAT(DISTINCT f.dimensioni ORDER BY f.id SEPARATOR " | ") as formati
FROM immagine i
LEFT JOIN immagine_has_formato fi ON fi.immagine_codice=i.codice
LEFT JOIN formato f ON f.id=fi.formato_id
LEFT JOIN keyword_has_immagine ki ON ki.immagine_codice=i.codice
LEFT JOIN keyword k ON k.id=ki.keyword_id
WHERE i.libro_codice = '06' AND i.codice IN (
SELECT ki.immagine_codice FROM keyword_has_immagine ki
INNER JOIN keyword k ON k.id=ki.keyword_id
WHERE lower(k.nome) = 'steam'
)
GROUP BY i.codice

There's any one that can help me? Thanks!..

2
  • Can you format the query to make it more readable? Commented Jul 26, 2010 at 8:55
  • Please format your SQL correctly Commented Jul 26, 2010 at 8:55

1 Answer 1

2

For subquerys, you can use this example as a basis:

...
$subselect = $this->select()->setIntegrityCheck(false);
        $subselect->from(array('e'=>'feed_entries'),array('e.id'))
                   ->join(array('f'=>'feeds'),'e.feed_id =f.id','')
                   ->join(array('ec'=>'entries_categorias'),'ec.entry_id =e.id','')
                   ->join(array('c'=>'categorias'),'ec.categoria_id =c.id','')
                   ->where('e.imagem332x332 =?',1)
                   ->where('e.deleted =?',0)
                   ->group('e.id')
                           ->where('c.nome IN(?)',$categories)
                       ->having('COUNT(DISTINCT ec.id) =?',count($categories));

$select = $this->select()->where('id IN ?',$subselect)->order('date DESC')->limit(4);
return $this->fetchAll($select);
...

For group_concat, I've never tried, but this page have some examples in the commments

Also, take a look at the Zend Db Expressions.

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

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.