What Mysql query will return this result?
- by Lost_in_code
I have two tables A,B which are related to each other (simplified):
A:
+-------+---------+
| id | type |
+-------+---------+
| 1 | apple |
| 2 | orange |
| 3 | banana |
+-------+---------+
B:
+-------+---------+-----------+
| id | a_id | rank |
+-------+---------+-----------+
| 1 | 1 | 0.0 |
| 2 | 1 | 7.7 |
| 3 | 2 | 3.3 |
| 4 | 2 | 8.8 |
| 5 | 2 | 1.1 |
| 6 | 3 | 3.3 |
| 7 | 3 | 5.5 |
| 8 | 1 | 9.5 |
+-------+---------+-----------+
What mysql query will return the following result?
Result
+-------+---------+-----------+
| id | type | rank |
+-------+---------+-----------+
| 1 | apple | 9.5 |
| 2 | orange | 1.1 |
| 3 | banana | 5.5 |
+-------+---------+-----------+