I
I
Ilya Kochkin2018-04-02 17:04:59
MySQL
Ilya Kochkin, 2018-04-02 17:04:59

How to get the number of records in a selection?

how do i count the number of rows in a fetch

SELECT
  tab_count.product_id,
  tab_count.total,
  ocp.status
FROM (SELECT
        product_id,
        count(product_id) AS total
      FROM oc_order_product
      GROUP BY product_id
      ORDER BY total DESC) AS tab_count,
  oc_product AS ocp
WHERE ocp.status = '1' AND ocp.product_id = tab_count.product_id
GROUP BY tab_count.product_id
ORDER BY tab_count.total DESC

in response I get this7_Jt0d9Vx_0.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iFawn, 2018-04-02
@iFawn

a separate query, for example:
SELECT count(*)
FROM (SELECT
product_id,
count(product_id) AS total
FROM oc_order_product
GROUP BY product_id
ORDER BY total DESC) AS tab_count,
oc_product AS ocp
WHERE ocp.status = '1' AND ocp.product_id = tab_count.product_id
GROUP BY tab_count.product_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question