SQL for user query fixed (I hope so)