Skip to content

Incorrect result when grouping by two columns with the same name with or without joins #941

Closed

Description

@besquared

The results to this query are just incorrect. One of the projected expressions ends up not being there and the other has the values intended for the missing one. Works in any situation where the column names are the same regardless of what else you do.

Examples here:
http://jsfiddle.net/tp3v4h86/4/

Activity

  1. mathiasrw commented on Dec 2, 2025

    @mathiasrw
    Member
    var accounts = [ 
        { name: 'A', region_id: 1  },
        { name: 'B', region_id: 2 }
    ];
    
    var regions = [
    	{ id: 1, name: 'North' },
      { id: 2, name: 'South' }
    ];
    
    // Do the query
    var result = alasql("SELECT accounts.name AS `AccountName`, regions.name AS `RegionName`, COUNT(1) AS `Count` FROM ? accounts LEFT JOIN ? regions ON accounts.region_id = regions.id GROUP BY accounts.name, regions.name", [accounts, regions]);
    
    document.getElementById("result").innerHTML = JSON.stringify(result);
    
    // An even simpler example
    
    var result2 = alasql("SELECT accounts.name AS `AccountName`, accounts.name AS `AccountName2`, COUNT(1) AS `Count` FROM ? accounts GROUP BY accounts.name", [accounts]);
    
    document.getElementById("result2").innerHTML = JSON.stringify(result2);
    
  2. added a commit that references this issue on Dec 3, 2025
    254bb8b
  3. added a commit that references this issue on Dec 4, 2025
    fc10673
  4. mathiasrw commented on Dec 6, 2025

    @mathiasrw
    Member

    Fix released as part of v4.11.0

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions