Trailing 'AND 1' seems unfortunate.  Don't you only need:
```
if (group > -1) q += "groupId = %1 ";
if (!token.isEmpty() || !mmsId.isEmpty()) q += "AND ";
```