Hi I got problem trying to generate football table based on last 4 matches results 
this is the code I'm using to generate table based on all results and it works fine:

```
select 
    team, 
    count(*) played, 
    count(case when goalsfor > goalsagainst then 1 end) wins, 
    count(case when goalsagainst> goalsfor then 1 end) lost, 
    count(case when goalsfor = goalsagainst then 1 end) draws, 
    sum(goalsfor) goalsfor, 
    sum(goalsagainst) goalsagainst, 
    sum(goalsfor) - sum(goalsagainst) goal_diff,
    sum(
          case when goalsfor > goalsagainst then 3 else 0 end 
        + case when goalsfor = goalsagainst then 1 else 0 end
    ) score 
from (
    select hometeam team, goalsfor, goalsagainst from scores 
  union all
    select awayteam, goalsagainst, goalsfor from scores
) a 
group by team
order by score desc, goal_diff desc;
```

this is table

```
 id  | hometeam | awaytem | goalsfor | goalsagainst | time | data
 1   | team a   | team b  |   3      |    2         | 13:00| 2016-04-21
 2   | team c   | team b  |   4      |    1         | 13:00| 2016-04-19
```

I have no idea how to select only 4 last games for all teams the most recent one
I tried that way: 

```
 (
    select hometeam team, goalsfor, goalsagainst from scores 
  union all
    select awayteam, goalsagainst, goalsfor from scores where data>2016-03-21
)
```

But some of the teams played only one game for that period others 4