skip to Main Content

/suppose that in a Table named Team contains 4 records,
we need to schedule a match between each team vs opposite team:
/
India
Pakistan
Srilanka
Australia

OUTPUT
Australia VS India
Australia VS Pakistan
India VS Pakistan
Australia VS Srilanka
Pakistan VS Srilanka
India VS Srilanka

3

Answers


  1. Chosen as BEST ANSWER
    select
     concat(team1,' ','VS',' ',team2) as Upcoming_Matches 
    from 
    (select
     a.team as team1 ,
     b.team as team2
    from testdata a,
         testdata b
    where a.team <> b.team and a.team < b.team) as newt
    

  2. Scheduling matches between 4teams . Using selfjoin joining the table to itself and then using comdition where table a not equal to table b then same team will not be matched to itself it will be filtered and then table a < table match won’t schedule with the same team .

    Login or Signup to reply.
  3. if string in first column is smaller than string in second column then it will return (eg; australia is smaller than india ) compare the first letter of the string .If both starts with same letter then look for the second letter . this is how it works . first execute the query without where condition .You will figure out the concept behind. Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search