代码之家  ›  专栏  ›  技术社区  ›  rahim asgari

将复杂的查询更改为Zend\u Db\u Select object

  •  2
  • rahim asgari  · 技术社区  · 15 年前

    (SELECT category_id AS id, content_title AS title, content AS detail, 'content' AS type
     FROM category_content
     WHERE $where
     ORDER BY id DESC)
    UNION
    (SELECT news_id AS id, news_title AS title, news_detail AS detail, 'news' AS type
     FROM news
     WHERE $where
     ORDER BY id DESC)
    

    如何将此查询更改为 Zend_Db_Select 反对?

    1 回复  |  直到 15 年前
        1
  •  2
  •   Bill Karwin    15 年前

    要使用Zend\u Db\u Select构建联合查询,请首先将每个子查询构建为单独的Zend\u Db\u Select对象,然后将它们联合起来:

    $catSelect = $db->select()-> ... ;
    $newsSelect = $db->select()-> ... ;
    
    $unionSelect = $db->select()->union($catSelect, $newsSelect);
    
    推荐文章