Skip to content
Advertisement

How could I use case within join and union?

I have 2 tables:

Matches

Rounds

Inserts

My query:

I would like to know

  • what places a particular team achieved (should probably use HAVING m.matchwinner = 'fnatic')

MatchID – Team – Place
1 – fnatic – 1st
3 – fnatic – 3rd
4 – fnatic – 3rd

  • what places all teams achieved

MatchID – Team – Place
1 – fnatic – 1st
2 – astralis – 1st
3 – fnatic – 3rd
4 – fnatic – 3rd
and so on

Don’t understand why my query isn’t working?

Advertisement

Answer

This looks like a join and conditional logic:

To get the same result for all teams, just remove the where clause.

Demo on DB Fiddle:

matchid | team   | place
------: | :----- | :----
      1 | fnatic | 1st  
      3 | fnatic | 3rd  
      4 | fnatic | 3rd  
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement