Mysqli random row in GROUP BY clause

I have the following query mysqli query by database:

SELECT a.num, a.general_num, a.url_alias, a.title
FROM m_catalog_products AS a
LEFT JOIN m_catalog_products_prices AS b ON a.num=b.num
LEFT JOIN m_catalog_products_colors AS c ON a.num=c.num
WHERE status = ‘1’
AND access = ‘guest’
AND a.categ = 61
GROUP BY a.general_num
ORDER BY IF(ind_price_4 > 0,ind_price_4,9999999) ASC
LIMIT 0,24;

The problem is that I have multiple variations of products that have the same “general_num” and I have to do group by that column because it’s all the same product and the only difference is in color and size.

Order by must be by price as it is, but the problem is that the query always retrieves the first product in “group by”, and I need a random product.

Ex. the products are 100100, 100101, 100102 … 100115 general num is here 1001, and this query always returns 100101, but I need some random (eg 100104).

EDIT: basically i have products with codes 100101, 100102, 100103, 1002104, 100105, 100106, 100107, 100108, 100109 … and they all have a column “general_num” identical (1001 - first four digits) and when I do “group by” query always I return the product 100101 (first one), but I would like to return one of these (100101,100102 … 100109) by random

Sponsor our Newsletter | Privacy Policy | Terms of Service