Reputation: 1498
I have table "teams" with fields: id, team_name
id, team_name
i want to select in one query all available VS combinations ...
like that:
Real Madrid - FC Barcelona
Real Madrid - juventus
Real Madrid - Milan
FC Barcelona - juventus
FC Barcelona - Milan
juventus - Milan
the purpose is to find solution for dynamic with different amount of rows if will be more teams in the tables...
this is possible? how... ?
Thanks :)
Upvotes: 0
Views: 58
Reputation: 49260
Use a self join
.
select t1.team_name,t2.team_name
from tbl t1
join tbl t2 on t1.team_name>t2.team_name --or if the id's are unique use
/* on t1.id < t2.id */
Upvotes: 5