Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Bug?】"Unknown column" ERROR in the ON condition in CROSS JOIN #376

Closed
hiroyuki0415 opened this issue Oct 23, 2023 · 1 comment · Fixed by #383
Closed

【Bug?】"Unknown column" ERROR in the ON condition in CROSS JOIN #376

hiroyuki0415 opened this issue Oct 23, 2023 · 1 comment · Fixed by #383

Comments

@hiroyuki0415
Copy link

The following SQL cannot be executed.

SELECT *
FROM   businessunit AS b CROSS APPLY (SELECT   TOP 1 s.systemuserid
                                      FROM     systemuser AS s
                                               INNER JOIN
                                               businessunit AS b1
                                               ON s.businessunitid = b1.businessunitid
                                                  AND b1.businessunitid = b.businessunitid --ERROR: "Unknown column: b.businessunitid"
                                      ORDER BY s.createdon DESC) AS newest_user;

Error message:

Unknown column: b.businessunitid

Thanks in advance for your support.

@hiroyuki0415 hiroyuki0415 changed the title 【Bug?】The alias of the table on the left cannot be used in the ON condition in CROSS JOIN 【Bug?】"Unknown column" ERROR in the ON condition in CROSS JOIN Oct 23, 2023
@MarkMpn
Copy link
Owner

MarkMpn commented Oct 24, 2023

Thanks, this will be fixed in the next update. In the meantime you can either move this predicate to the WHERE clause:

SELECT *
FROM   businessunit AS b CROSS APPLY (SELECT   TOP 1 s.systemuserid
                                      FROM     systemuser AS s
                                               INNER JOIN
                                               businessunit AS b1
                                               ON s.businessunitid = b1.businessunitid
                                      WHERE    b1.businessunitid = b.businessunitid
                                      ORDER BY s.createdon DESC) AS newest_user;

or remove the join entirely:

SELECT *
FROM   businessunit AS b CROSS APPLY (SELECT   TOP 1 s.systemuserid
                                      FROM     systemuser AS s
                                      WHERE    s.businessunitid = b.businessunitid
                                      ORDER BY s.createdon DESC) AS newest_user;

MarkMpn added a commit that referenced this issue Oct 25, 2023
@MarkMpn MarkMpn mentioned this issue Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants