fix params to select and fix SQL by using subquery
Merge pull request #970 from Wikia/CON-47

CON-47: Fix params to select and fix SQL by using subquery