Turning MQLs into SQLs