Explaining my MySQL issue in words is tough for me as a beginner, and finding solutions is proving really challenging.
This problem is much clearer when seen visually:
I am trying to select exchange_pair_id's that have the same pair_id to form an array.
https://i.sstatic.net/NKG02.png
So based on the data above, my MySQL query would result in an object:
{ pair_id: 1, exchange_pair_id: [183, 1] }
I understand this might not be the most clear question, but I'm struggling to find the right search terms to solve it.
Updated for clarification/brevity:
+------------------+-------------+---------+
| exchange_pair_id | exchange_id | pair_id |
+------------------+-------------+---------+
| 1 | 3 | 1 |
+------------------+-------------+---------+
| 183 | 1 | 1 |
+------------------+-------------+---------+
| 69 | 2 | 2 |
+------------------+-------------+---------+
| 12 | 4 | 2 |
+------------------+-------------+---------+
| 2 | 3 | 2 |
+------------------+-------------+---------+
| 3 | 3 | 3 |
+------------------+-------------+---------+
Desired outcome from a JavaScript MySQL select query:
[
{ pair_id: 1, exchange_pair_id: [1, 183] },
{ pair_id: 2, exchange_pair_id: [69, 12, 2] },
{ pair_id: 3, exchange_pair_id: [3] }
]