Question: I need to calculate a count on a query, however I got some problem.

The original query works well.  

It gives me 1 row with the right count (3200):

```
select count(e.entity_id) 
from `catalog_product_entity` AS `e`
INNER JOIN `review` AS `rt` 
ON rt.entity_pk_value = e.entity_id
INNER JOIN `review_detail` AS `rdt` 
ON rdt.review_id = rt.review_id
INNER JOIN `review_store` AS `store` 
ON rt.review_id=store.review_id AND store.store_id=0

```

I needed to alter this query in order to get other values so now, this is the new count query:

```
select count(e.entity_id) 
from `catalog_product_entity` AS `e`
INNER JOIN `review` AS `rt` 
ON rt.entity_pk_value = e.entity_id
INNER JOIN `review_detail` AS `rdt` 
ON rdt.review_id = rt.review_id
LEFT JOIN `rating_option_vote` AS `vt` 
ON vt.review_id = rt.review_id
INNER JOIN `review_store` AS `store` 
ON rt.review_id=store.review_id AND store.store_id=0 
GROUP BY `rt`.`review_id`

```

Second query gives me back not 1 row with the correct count (3200) but 3200 rows with each one with a different count.

What I would need it would be something like:

```
SELECT COUNT (*) FROM
( `second_query`)

```

Or any other solution that gives me back the right count

Answer: 
Try this

```
select TOP 1 count(e.entity_id) OVER() [Total Count]
from `catalog_product_entity` AS `e`
INNER JOIN `review` AS `rt` 
ON rt.entity_pk_value = e.entity_id
INNER JOIN `review_detail` AS `rdt` 
ON rdt.review_id = rt.review_id
LEFT JOIN `rating_option_vote` AS `vt` 
ON vt.review_id = rt.review_id
INNER JOIN `review_store` AS `store` 
ON rt.review_id=store.review_id AND store.store_id=0 
GROUP BY `rt`.`review_id`

```

or 

```
SELECT COUNT(*)
FROM 
(select `rt`.`review_id`
from `catalog_product_entity` AS `e`
INNER JOIN `review` AS `rt` 
ON rt.entity_pk_value = e.entity_id
INNER JOIN `review_detail` AS `rdt` 
ON rdt.review_id = rt.review_id
LEFT JOIN `rating_option_vote` AS `vt` 
ON vt.review_id = rt.review_id
INNER JOIN `review_store` AS `store` 
ON rt.review_id=store.review_id AND store.store_id=0 
GROUP BY `rt`.`review_id`) AS T1

```
Take away the group by clause.