I have a table with the following fields:
- id
- code
- category
- web_sales
- brand
I want to show only random code in Laravel and group it by category but that the code is generated randomly.
The problem is this: how do I group the category and bring a random code grouping the category?
I have the query as follows:
SELECT codigo,categoria
FROM 'vcomp_productos_web1'
WHERE venta_web = "SI" AND marca = "VERA"
GROUP BY categoria
ORDER BY rand()
But it shows me the following table:
How do I get the code generated randomly? I have consulted and it is done with Rand(codigo)
the first code is always chosen and I need any code, but I can not find the solution.