Shravan Jain Shravan Jain - 1 month ago 11
SQL Question

SQL for getting each category data in maria db

I need to fetch 4 random values from each category. What should be the correct sql syntax for maria db. I have attached one image of table structure.

Please click here to check the structure

Should i write some procedure or i can do it with basic sql syntax?

Answer
SELECT column FROM table WHERE category_id = XXX 
ORDER BY RAND() 
LIMIT 4

do it for all categories

Comments