sql - How to combine two rows in one in PostgreSQL? -


i'm selecting data 2 tables in postgres in way:

select matches.id id, first_team_id t1, second_team_id t2, name  matches  join teams on matches.first_team_id = teams.id  union  select matches.id id, first_team_id t1, second_team_id t2, name  matches  join teams on matches.second_team_id = teams.id 

that's how table looks now:

id  t1  t2  name 1   1   2   team1 1   1   2   team2 2   1   3   team2 2   1   3   team1 

that's need

id  t1  t2  name1  name2 1   1   2   team1  team2 2   1   3   team2  team1 

i need easiest way it. i've seen solutions in similar questions, didn't manage them. please me

you can want 2 joins:

select m.id, m.first_team_id, m.second_team_id, t1.name, t2.name matches m join      teams t1      on m.first_team_id = t1.id join      teams t2      on m.second_team_id = t2.id; 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -