doing two mysql requests in one I have this two working queries:

select distinct(foo) from my_table;

+--------------------------------------------------+
| foo                                              |
+--------------------------------------------------+
| bar1                                             |
| bar2                                             |
| ...                                              |
+--------------------------------------------------+


And:

select   foo, sum(position)/count(position) as average_position
from     (select   foo, position
          from     my_table
          where    foo = 'bar1'
          order by date desc limit 3) as subquery
group by foo;

+------------------+------------------+
| foo              | average_position |
+------------------+------------------+
| bar1             |           8.3333 |
+------------------+------------------+


And now I would like to do this in one request, so I want to do my second request for each distinct foo in one request.

OUTPUT must be:

+------------------+------------------+
| foo              | average_position |
+------------------+------------------+
| bar1             |           8.3333 |
| bar2             |           7.0000 |
| ...              |           ...... |
+------------------+------------------+


How I can achieve this?
Depending on how many values you have for the 'foo' column, you may be able to accomplish this with a union:

select   foo, sum(position)/count(position) as average_position
from     (
    select   foo, position
    from     my_table
    where    foo = 'bar1'
    order by date desc limit 3
union all
    select   foo, position
    from     my_table
    where    foo = 'bar2'
    order by date desc limit 3
) as subquery
group by foo;