What Mysql query will return this result?

Posted by Lost_in_code on Stack Overflow See other posts from Stack Overflow or by Lost_in_code
Published on 2010-05-29T22:49:58Z Indexed on 2010/05/29 22:52 UTC
Read the original article Hit count: 173

Filed under:

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      | 
+-------+---------+-----------+ 

© Stack Overflow or respective owner

Related posts about mysql