Skip to content

JOIN returns incorrect result when used with nested SELECT #1263

Closed

Description

@akhaneev

Here is a test:

if (typeof exports === 'object') {
    var assert = require('assert');
    var alasql = require('..');
} else {
    __dirname = '.';
}

describe('Test 813 - Nested SELECT', function () {
    var t1 = [
        {id: '1', a: 'one'},
        {id: '2', a: 'two'},
        {id: '3', a: 'three'},
        {id: '4', a: 'four'},
    ];
    var t2 = [
        {id: '1', b: 'A'},
        {id: '2', b: 'B'},
        {id: '5', b: 'E'},
        {id: '6', b: 'F'},
    ];

    it('1. JOIN', function (done) {
        var expected = [
            {id: '1', a: 'one', b: 'A'},
            {id: '2', a: 'two', b: 'B'},
            {id: '3', a: 'three'},
            {id: '4', a: 'four'},
            {id: '5', b: 'E'},
            {id: '6', b: 'F'},
        ];

        var res = alasql(
            'SELECT * FROM ? T1 OUTER JOIN ? T2 ON T1.id = T2.id',
            [t1, t2]
        );
        assert.deepEqual(res, expected);

        var res = alasql(
            'SELECT * FROM ? T1 OUTER JOIN (SELECT * FROM ?) T2 ON T1.id = T2.id',
            [t1, t2]
        );
        assert.deepEqual(res, expected);
        done();
    });

});

Activity

  1. mathiasrw commented on Dec 5, 2020

    @mathiasrw
    Member

    Thank you so much for identifying this bug so precise.

  2. journeytoday commented on Sep 24, 2023

    @journeytoday

    Hi @akhaneev @mathiasrw this is closed but shows open in good first issue, is this by design or a bug?

  3. added a commit that references this issue on Sep 25, 2023
  4. mathiasrw commented on Sep 25, 2023

    @mathiasrw
    Member

    @journeytoday Great work picking this up. I added the test from this PR and I can see that its working as expected. Will close this one. Thank you for pinging me on this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions