Search code examples
mysqlsqldatabasejoinsubquery

SQL query join or subquery


[![table named teams and Matchesenter image description here ][2]][2]I have 2 tables

[2]: https://i.sstatic.net/7v4nT.png**strong text**

I need data from these 2 tables in such a ways that a new table is formed with the following data

mid, result, date, team1id, team2id from matches table on the basis of tourid=6 and from table of team i need to show the Tname as team1 and Tname as team2.


Solution

  • Sounds like you need a join:

    select matches.*,t1.Tname as team1,t2.Tname as team2 from matches
    join team t1 on t1.Teamid=matches.team1id
    join team t2 on t2.Teamid=matches.team2id
    where tourid=6