Some of the queries work in 5.6 and but not on 5.7.
Basically the only difference between the two is the parenthesis in the second query around the first select with the LIMIT.
Without parenthesis they work in 5.6 but if i use on 5.7 i am getting error:
ERROR 1221 (HY000): Incorrect usage of UNION and LIMIT
any idea how to get this fixed.