title: How to combine two rows in one in PostgreSQL?
body: <p>I'm selecting data from 2 tables in postgres in this way:</p>
  
  <pre><code>SELECT matches.id id, first_team_id T1, second_team_id T2, name 
  FROM matches 
  JOIN teams ON matches.first_team_id = teams.id 
  UNION 
  SELECT matches.id id, first_team_id T1, second_team_id T2, name 
  FROM matches 
  JOIN teams ON matches.second_team_id = teams.id
  </code></pre>
  
  <h3>That's how my table looks now:</h3>
  
  <pre><code>id  T1  T2  name
  1   1   2   Team1
  1   1   2   Team2
  2   1   3   Team2
  2   1   3   Team1
  </code></pre>
  
  <h3>That's what i need</h3>
  
  <pre><code>id  T1  T2  name1  name2
  1   1   2   Team1  Team2
  2   1   3   Team2  Team1
  </code></pre>
  
  <p>I need the easiest way to do it. I've seen some solutions in similar questions, but i didn't manage with them. Please help me</p>