Getting Connection Lost in coorelated queries.
select emp_no,salary
from salaries e
where 2 =
(select count(distinct salary) from salaries p where p.salary>e.salary);
I tried this to get second highest salary but its giving me sql connection lost every time. All other queries are working fine except this one.
I m using sql workbench.
Attached: Screenshot of error
It looks like the connection has a 30 second time out, and the inefficient query is taking too long. This way is much faster, and should finish before the timeout:
Eventually, if MySQL properly implements the ANSI
QUALIFYkeyword this might need even less code and run even a little faster.