hi i have a sold table in my db , my table looks like this :
+-----------+---------------------+---------+---------+
| id | product_id | user_id | date |
+-----------+---------------------+---------+---------+
| 1 | 20 | 2 |392185767|
+-----------+---------------------+---------+---------+
| 2 | 28 | 3 |392333337|
+-----------+---------------------+---------+---------+
i want to want to sort table output by most purchased products
something like :
$sql = "select * from sold order by most_repeated(product_id)";
i don’t want to group the out put by product id , i just want to sort them so the most repeated products shows at the top of result
Since you do not want to group by, you could use a correlated query:
I have not tried this in MySQL, but it should work.