Originariamente inviato da Toniello
Ok per l'HAVING ti ringrazio.
Il problema e' che se tolgo il raggruppamento per m.roundinfo avro' sicuramente SEMPRE piu' di 5 match, perche' mi fa il count totale tra tutti i round che possono essere anche 38.
Il group by deve restare cosi, pero' vorrei evitare di estrapolare tutto e ciclarlo con PHP
qualcosa mi sfugge. un id dovrebbe essere per definizione chiave primaria e quindi unico.
Group by t.id conta quindi i record della tabella t che hanno riferimento con la tabella m
Se vuoi il solo m.roundinfo minore prova ad usare MIN(m.roundinfo) raggruppando per m.id invece di t.id
e' solo tentativo perche' non conosco il tuo progetto.
codice:
select count(m.id) as matchnumber, t.id, t.name, MIN(m.roundinfo) as roundinfo
from tournament as t
join matchlist as m on (m.tournament_id = t.id)
where m.date >= CURDATE() $where
group by m.id
HAVING matchnumber > 5
order by m.roundinfo asc
puoi anche usare l funzione curdate() invece di date() del php