TLE- Union distinct.


  • 0
    W

    TLE: Tried the obvious way using or in a basic query. Then tried subquery and I couldn't get the syntax to work. Lastly tried this, and I'm pretty sure the issue is the "union distinct" but Not sure how to eliminate the duplicate. 4/5 cases work in allowed time.

    select name, population, area 
    from World
    where area > 3000000
    Union distinct
    select name, population, area
    from World
    where population > 25000000;

  • 0
    S

    I also tried a similar approach with exact same results. 4/5 test cases pass.

    Select name, population, area
    from World
    where population>25000000
    or area > 3000000


  • 0

    This is just fixed.


  • 0
    W

    @1337c0d3r

    Thank you, was there an intended way that you wanted to be faster? What would you recommend?


  • 0
    J

    @1337c0d3r This seems straight forward approach which includes 3 columns in select statement with two conditions using OR.
    Then why this running time variations are different ? Could you please let us know optimized query which beats > 90% of solutions.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.