I have a product table and a memory table. The product table contains product ID and product name:
| product_id | product |
|---|---|
| 1 | RAM |
| 2 | HDD |
| 3 | SSD |
The memory table contains different memory as below:
| memory_id | memory |
|---|---|
| 1 | 128 GB |
| 2 | 256 GB |
| 3 | 512 GB |
| 4 | 1 TB |
| 5 | 8 GB |
| 6 | 16 GB |
| 7 | 32 GB |
I have created two drop-down select options for products and for memory and save them in a cart table as below:
| order_id | product_id | memory_id |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 1 | 1 |
| 4 | 2 | 3 |
| 5 | 2 | 4 |
| 6 | 2 | 3 |
I am wondering is there any way to do DESC order the select options for memory based on the occurrence of that specific product_id in cart table?
My target is to order the select options of the memory with the most used cases.