Fix 'LIMIT 1' clause in subquery gets stripped off

Implementing the fix proposed in
http://phplens.com/lens/lensforum/msgs.php?id=17813