[BUG] Fixed bug in SQL Query - Closes #40