title: Count issue with two tables in mysql
body: <p>i want to get number of records from two tables having less than 3 pics.here is what i have tried but this is not working well</p>
  
  <pre><code>SELECT
      SUM(tot_rent) AS tot_rent
      FROM (
      SELECT
              COUNT(id) AS tot_rent
          FROM crm_rentals_images
          GROUP BY rentals_id
          HAVING COUNT(*) &lt;3
      UNION
      SELECT
              COUNT(id) AS tot_rent
          FROM crm_sales_images
          GROUP BY rentals_id
          HAVING COUNT(*) &lt;3
      ) s
  </code></pre>
  
  <p>what is missing?when i am comparing with real data,it do not show correct result</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `crm_rentals_images` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `image` varchar(22) NOT NULL,
  `rentals_id` int(22) DEFAULT NULL,
   PRIMARY KEY (`id`)
   ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
  
  INSERT INTO `crm_rentals_images` (`id`, `image`, `rentals_id`) VALUES
  (1, 'a.jpg', 1),
  (2, 'b.jpg', 1),
  (3, 'a.jpg', 1),
  (4, 'b.jpg', 1),
   (5, 'a.jpg', 2),
  (6, 'b.jpg', 2),
  (7, 'a.jpg', 4),
  (8, 'b.jpg', 4),
  (9, 'a.jpg', 3),
  (10, 'b.jpg', 3);
  </code></pre>