Utkarsh Sharma Utkarsh Sharma - 2 months ago 5
MySQL Question

how to fetch random stores name but price in ascending order from database?


how to use fetch 'food_store' order by randomly and price order by ASC ?
write now i am using this query


Select * from `food` where `veg_non` = 'Veg' and `food_price` <= ? ORDER BY RAND()

Answer

Try this:

Select *, RAND() as r from `food` where `veg_non` = 'Veg'
    and `food_price` <= ? ORDER BY `food_price` ASC, r ASC
Comments