Weather Observation Station 5

  • + 1 comment

    in MS SQL SERVER:
    why does this work:

    select top 1 city, len(city) as short_len from station order by short_len, city asc;
    select top 1 city, len(city) as long_len from station order by long_len desc;
    

    and not this:

    (select top 1 city, len(city) as short_len from station order by short_len, city asc)
    union
    (select top 1 city, len(city) as long_len from station order by long_len desc);
    

    I get this Runtime Error:

        Msg 156, Level 15, State 1, Server dbrank-tsql, Line 6
    
        Incorrect syntax near the keyword 'order'.
    
        Msg 156, Level 15, State 1, Server dbrank-tsql, Line 8
    
        Incorrect syntax near the keyword 'order'.