CON-1239 | fixed MySQL query