1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Unique problem

Discussion in 'MySQL' started by Its_TV, Apr 26, 2020.

  1. #1
    Hello,
    Im Creating a soccer database. Im create my gameplan out of my Teams table. On table Game i set Home and away Team on unique. Now im use a Procedure to fill games per gameday in the table Game. Problem is here sql cremte Game 1 Dortmund – Bayern and next game is Bayern – Dortmund on the Same gameday. How Can I set unique That this Cant be done?
     
    Its_TV, Apr 26, 2020 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Your unique needs to be an id rather than the teams.
    Don't be afraid to mess about and try different things to get it working the way you need.
     
    sarahk, Apr 26, 2020 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Did not completely understood what you are trying to do, but if you want a unique team on a particular gameday, then your fill procedure must do that check before inserting record of another team on same gameday.
     
    JEET, Apr 27, 2020 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #4
    If they're having a club champs it's possible for teams to play in a "pool" round and then meet again in the quarter finals etc.
     
    sarahk, Apr 27, 2020 IP
    JEET likes this.
  5. Its_TV

    Its_TV Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    Problem is. Gameday 1
    Dormunt-Bayern (Fine)
    Bayern - Dortmund (not fine)
    Köln - Gladbach (Fine)
    Gladbach - Köln (Not Fine)

    With 4 team there should be only 2 game per gameday.

    so with unique I didn’t insert all other matches. But there the unique didn’t work
     
    Its_TV, Apr 27, 2020 IP
  6. Its_TV

    Its_TV Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    this is my code

    #Temporary table
    create temporary table alleSpiele as ( select t1.name as heim, t2.name as gast from (select Name from Verein) as t1, (select Name from Verein) as t2 where t1.Name != t2.Name);

    #unique
    create temporary table alleSpiele as ( select t1.name as heim, t2.name as gast from (select Name from Verein) as t1, (select Name from Verein) as t2 where t1.Name != t2.Name);

    #procedure
    delimiter //

    create procedure spieltag (in spieltag int)
    BEGIN

    declare finished int default 0;
    declare ende int default 0;
    declare team1 varchar(45) default null;
    declare team2 varchar(45) default null;

    declare vereinscursor cursor for select Heim, Gast from alleSpiele;
    declare continue handler for not found set finished := 1;
    declare continue handler for 1062 set ende := 1;

    open vereinscursor;

    repeat
    fetch vereinscursor into team1, team2;

    if finished = 0 then
    insert into Spiel (Spieltag, Datum, Uhrzeit, Heim, Gast) values (spieltag, current_date(),'15:30',team1,team2);
    end if;
    until finished = 1
    END repeat;

    close vereinscursor;

    END//
     
    Its_TV, Apr 27, 2020 IP
  7. Its_TV

    Its_TV Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    upload_2020-4-27_13-52-22.png

    this is the result
     
    Its_TV, Apr 27, 2020 IP