Problems stopping tables with UNION

0

I'm trying to get the top 3 from my table and also the last 2 placed, SITE TO RUN SCRIPT

This is my current progress that does not work

SELECT ('Podium: ' ||TEAM) as name  
FROM LEAGUE
ORDER BY position ASC LIMIT 3;
  UNION ALL
SELECT ('Demoted: ' ||TEAM) as name 
FROM LEAGUE
ORDER BY position DESC LIMIT 2;

I made a fiddle base for anyone who wants to help me.    

    CREATE TABLE league
        (
            position INTEGER PRIMARY KEY NOT NULL,
            team VARCHAR(45)
        );
    
   INSERT INTO league VALUES(1, 'The Quack Bats');
    INSERT INTO league VALUES(2, 'The Responsible Hornets');    
    INSERT INTO league VALUES(3, 'The Bawdy Dolphins'); 
    INSERT INTO league VALUES(4, 'The Abstracted Sharks');  
    INSERT INTO league VALUES(5, 'The Nervous Zebras'); 
    INSERT INTO league VALUES(6, 'The Oafish Owls');    
    INSERT INTO league VALUES(7, 'The Unequaled Bison');    
    INSERT INTO league VALUES(8, 'The Keen Kangaroos'); 
    INSERT INTO league VALUES(9, 'The Left Nightingales');  
    INSERT INTO league VALUES(10, 'The Terrific Elks'); 
    INSERT INTO league VALUES(11, 'The Lumpy Frogs');   
    INSERT INTO league VALUES(12, 'The Swift Buffalo'); 
    INSERT INTO league VALUES(13, 'The Big Chargers');  
    INSERT INTO league VALUES(14, 'The Rough Robins');  
    INSERT INTO league VALUES(15, 'The Silver Crocs');
    
asked by anonymous 17.04.2018 / 19:48

1 answer

2

Try this:

  SELECT position,
         'Podium' AS tipo,
         team
    FROM (SELECT *
            FROM league
           ORDER BY position ASC LIMIT 3) v
   UNION
  SELECT position,
         'Demoted' AS tipo,
         team
    FROM (SELECT *
            FROM league
           ORDER BY position DESC LIMIT 2) v

ORDER BY 1;
    
17.04.2018 / 20:07