title: How can I get Zend_Db to select one column only from a large query?
body: <p>I have a fairly complex query in SQL that performs a count across two tables. The query should look like this:</p>
  
  <pre><code>SELECT 
  ((SELECT COUNT(DISTINCT(pages.id)) AS `count` 
      FROM `pages` 
      INNER JOIN `pageRegions` ON pageRegions.pageId = pages.id 
      WHERE (MATCH (pages.name, pageRegions.contents) AGAINST ('+keyword*' IN BOOLEAN MODE))) + 
  (SELECT COUNT(documents.id) AS `count` 
      FROM `documents` 
      INNER JOIN `files` ON files.id = documents.file 
      WHERE (MATCH (documents.name, 
                files.name, 
                files.extracted_text) AGAINST ('+keyword*' IN BOOLEAN MODE)))) AS count
  </code></pre>
  
  <p>Unfortunately when I have the following code using Zend_Db the query includes a load of additional columns so the addition of both queries obviously fails:</p>
  
  <pre><code>$total_count_select = $PagesTable-&gt;getAdapter()
      -&gt;query('((' . $pages_total_count_select . ') + 
                (' . $legal_resources_total_count_select . ')
               ) AS count');
  </code></pre>
  
  <p>Where <code>$pages_total_count_select</code> and <code>$legal_resources_total_count_select</code> are both <code>Zend_Db_Select</code> objects.</p>
  
  <p>I have tried using the <code>columns()</code> method to specify the columns I want on each select object like so:</p>
  
  <pre><code>$legal_resources_total_count_select-&gt;columns('COUNT(documents.id) AS count');
  </code></pre>
  
  <p>But this just appears to append onto the select query rather than only returning the column specified.</p>
  
  <p>So the Zend generated query ends up looking like this:</p>
  
  <pre><code>SELECT ((SELECT `pages`.*, 
                   ((1.3 * (MATCH(pages.name) AGAINST ('+keyword*' IN BOOLEAN MODE))) + 
                         (0.8 * (MATCH(pageRegions.contents) AGAINST ('+keyword*' IN BOOLEAN MODE)))) AS `score`, 
                       `pages`.`name` AS `page_name`, 
                       `pages`.`id` AS `page_id`, 
                       `pageRegions`.*, 
                       COUNT(DISTINCT(pages.id)) AS `count`
           FROM `pages`
           INNER JOIN `pageRegions` ON pageRegions.pageId = pages.id
           WHERE (MATCH (pages.name, pageRegions.contents) AGAINST ('+keyword*' IN BOOLEAN MODE))
           ORDER BY `score` DESC)
  
              + 
  
            (SELECT `documents`.*,
                     ((1.3 * (MATCH(documents.title) AGAINST ('+keyword*' IN BOOLEAN MODE))) + 
                         (0.8 * (MATCH(documents.short_description, files.NAME, files.extracted_text) AGAINST ('+keyword*' IN BOOLEAN MODE)))) AS `score`,
                       `files`.*, 
                      COUNT(documents.id) AS `count`
           FROM `documents`
           INNER JOIN `files` ON files.id = documents.file
           WHERE (MATCH (documents.title, documents.short_description, files.name, files.extracted_text) AGAINST ('+keyword*' IN BOOLEAN MODE))
           ORDER BY `score` DESC)
          ) AS COUNT
  </code></pre>
  
  <p>How can I get rid of all the extra columns it is selecting?</p>