How to retrieve data of two columns from two tables

query

I have two Table MATCH_MASTER and TEAM_MASTER

MATCH_MASTER

|---------------------------|
|M_ID | TEAM1_ID | TEAM2_ID |
|---------------------------|
|  1  |     1    |     2    |

TEAM_MASTER

|T_ID | T_NAME |
|--------------|
|  1  |    A   |
|  2  |    B   |

I want to select M_ID, team1 name and team2 name.

My query result should look like this:

|------------------------|
|M_ID | t1_Name | t2Name |
|------------------------|
|  1  |    A    |   B    |

How can I achieve this?

Best Answer

Try following.

select T1.M_ID, 
    (select T2.T_NAME from TEAM_MASTER as T2 
    where T1.TEAM1_ID = T2.T_ID) as t1_Name,
    (select T2.T_NAME from TEAM_MASTER as T2 
    where T1.TEAM2_ID = T2.T_ID) as t2Name
    from MATCH_MASTER as T1;