SQL query


			
SELECT challenges.goal_type, challenges.goal_value, min(achievements.score) 
FROM challenges INNER JOIN achievements 
ON challenges.id = achievements.challenge_id 
WHERE ((achievements.user_id = 1)) 
GROUP BY challenges.goal_type, challenges.goal_value;

output


			
 goal_type | goal_value |       min        
-----------+------------+------------------
         1 |          3 | 2108.62817033333
         1 |         10 |      273.2031039
         1 |          5 |                 
         2 |          1 |    505403.234299
         4 |        0.1 |                 
         1 |         20 |    32441.5453999
         3 |         10 |      124.2600446
         3 |         30 | 116.657539166667

Problem


			
The returned results are expected for the SQL query. The problem is,
achievements has more columns than just score. I want to return the
rest of the achievements columns that coincide with the score but 
only base the results returned on the achievements score. basically, 
I need to return this...

 goal_type | goal_value |       min        | data  |
-----------+------------+------------------+-------+
         1 |          3 | 2108.62817033333 | some  |
         1 |         10 |      273.2031039 | extra |
         1 |          5 |                  | data  |
         2 |          1 |    505403.234299 | from  |
         4 |        0.1 |                  | achie |
         1 |         20 |    32441.5453999 | table |
         3 |         10 |      124.2600446 |       |
         3 |         30 | 116.657539166667 |       |

Returning the exact same rows from challenges and achievements, but 
including additional columns from achievements as well.

challenges table


			
 id | goal_type | goal_value 
----+-----------+------------
  1 |         1 |         10
  2 |         1 |         20
  3 |         2 |          1
  4 |         3 |         30
  5 |         1 |          5
  6 |         3 |         10
  7 |         1 |          3
  8 |         4 |        0.1

achievements table


			
 id | user_id | challenge_id |      score       |        finished_at         |         created_at         
----+---------+--------------+------------------+----------------------------+---------------------------
  1 |       1 |            1 |      389.6800391 | 2007-12-12 07:40:35.700136 | 2007-12-12 06:35:38.899745 
  2 |       1 |            1 |      732.3525193 | 2007-12-12 08:44:06.051999 | 2007-12-12 06:42:02.526806 
  3 |       1 |            1 |      273.2031039 | 2007-12-12 07:30:22.644592 | 2007-12-12 06:44:50.613553 
  4 |       1 |            1 |      363.8889239 | 2007-12-12 07:46:31.924187 | 2007-12-12 06:45:53.034948 
  5 |       1 |            2 |    32441.5453999 | 2007-12-19 19:11:35.424122 | 2007-12-12 06:57:44.516127 
  6 |       1 |            3 |    505403.234299 | 2007-12-20 02:43:59.153459 | 2007-12-14 06:20:35.919019 
  7 |       1 |            3 |                  |                            | 2007-12-20 02:49:15.711244 
  8 |       1 |            1 |                  |                            | 2007-12-20 03:31:58.376052 
 10 |       1 |            5 |                  |                            | 2007-12-20 14:23:41.132123 
 13 |       1 |            8 |                  |                            | 2007-12-20 14:25:49.80893  
 11 |       1 |            6 |      124.2600446 | 2007-12-20 14:45:27.99831  | 2007-12-20 14:24:45.397723 
  9 |       1 |            4 | 116.657539166667 | 2007-12-20 15:20:58.428912 | 2007-12-20 14:22:38.702597 
 12 |       1 |            7 | 2108.62817033333 | 2007-12-20 16:10:45.895706 | 2007-12-20 14:25:20.011053