Bug 916229 - proposing a patch to fix the bug.

Please reformat the SQL statement so that it's easier to read, e.g. use http://sqlformat.org.