Skip to content

UNION with ORDER BY doesn't seem to work as expected #2414

Closed

Description

@4skinSkywalker

If I do

SELECT country, COUNT(*) AS competitors
FROM foreignCompetitors
GROUP BY country
ORDER BY country
UNION
SELECT "Total: " AS country, COUNT(*) AS competitors
FROM foreignCompetitors;

I get error: Parse error on line 6: ...Y countryORDER BY UNIONSELECT "Total: ---------------------^ Expecting 'LITERAL', 'BRALITERAL', 'LPAR', 'NUMBER', 'STRING', 'SHARP', 'DOLLAR', 'AT', 'VALUE', 'COLON', 'NOT', 'IF', 'PLUS', 'STAR', 'QUESTION', 'INSERTED', 'FIRST', 'LAST', 'DELETED', 'CURRENT_TIMESTAMP', 'CURRENT_DATE', 'JAVASCRIPT', 'NEW', 'CAST', 'CONVERT', 'SUM', 'TOTAL', 'COUNT', 'MIN', 'MAX', 'AVG', 'AGGR', 'ARRAY', 'REPLACE', 'DATEADD', 'DATEDIFF', 'TIMESTAMPDIFF', 'INTERVAL', 'TRUE', 'FALSE', 'NSTRING', 'NULL', 'EXISTS', 'ARRAYLBRA', 'BRAQUESTION', 'CASE', 'TILDA', 'MINUS', 'ATLBRA', 'LCUR', got 'UNION'

If I remove the ORDER BY clause it works.

Activity

  1. changed the title [-]UNION doesn't seem to work as expected[/-] [+]UNION with ORDER BY doesn't seem to work as expected[/+] on Dec 25, 2025
  2. mathiasrw commented on Jan 8, 2026

    @mathiasrw
    Member

    A fix to this has been released as part of v4.17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions