Tell me how to select a database of certain categories of 8 products from a MySQL database.

Table

ID | CAT | NAME | DESCRIPTION |

CAT - from 1 to 7, select 8 products of each category

    1 answer 1

    Try this:

    SELECT t1.*, COUNT(*) num FROM MY_TABLE t1 JOIN MY_TABLE t2 ON t1.CAT = t2.CAT AND t1.ID >= t2.ID GROUP BY t1.CAT, t1.ID HAVING COUNT(*) <= 8 ORDER BY CAT, ID 
    • Thank you, closer to what I need - Cone Enoc