Skip to content

LEFT JOIN with a subquery in ON throws a TypeError #2795

Closed

Description

@mathiasrw

A subquery in the ON condition of a LEFT JOIN throws a TypeError.

Seen in the NIST SQL Test Suite run in dml148.sql: SELECT XX.PNUM, BUDGET, HOURS, EMPNUM FROM HU.PROJ XX LEFT JOIN HU.WORKS YY ON XX.PNUM = YY.PNUM AND HOURS * BUDGET / 160000 > (SELECT GRADE FROM HU.STAFF WHERE YY.EMPNUM = HU.STAFF.EMPNUM). Reproduced on develop (38bf3c3):

alasql("CREATE TABLE staff (empnum CHAR(3), grade INT)");
alasql("INSERT INTO staff VALUES ('E1', 12), ('E2', 10)");
alasql("CREATE TABLE works (empnum CHAR(3), hours INT)");
alasql("INSERT INTO works VALUES ('E1', 40), ('E2', 20)");
alasql('SELECT s.empnum, w.hours FROM staff s LEFT JOIN works w ON s.empnum = w.empnum AND w.hours > (SELECT MIN(hours) FROM works)');
// TypeError: undefined is not an object (evaluating 'this.queriesfn[0]')

Expected: [{empnum: 'E1', hours: 40}, {empnum: 'E2'}] (no match for E2, so hours is NULL).

Breaking?

No. Today it throws.

Activity

  1. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I'd like to work on this one.

  2. mateuscmtropical commented on Nov 11, 2026

    @mateuscmtropical
    Contributor

    Hi, I've opened a PR for this: #2992

  3. added this to the v4.x Focus milestone on Nov 15, 2026
  4. added a commit that references this issue on Nov 17, 2026
    43b87e0
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions