Using proper SQL query by @CaptainAK

Proposed fix did not work, using proper Query now.
Thank @CaptainAK for the fix!

Fixes #492