MarkMpn / Sql4Cds

SQL 4 CDS core engine and XrmToolbox tool
MIT License
75 stars 22 forks source link

【Bug】SQL NOT working correctly when using same alias name in the main query and subquery #350

Closed hiroyuki0415 closed 1 year ago

hiroyuki0415 commented 1 year ago
SELECT s.fullname,
       b_s.fullname
FROM   businessunit AS b
       INNER JOIN
       systemuser AS s
       ON b.businessunitid = s.businessunitid
          AND s.fullname LIKE 'AAA%'
       INNER JOIN
       (SELECT b.businessunitid,
               s.fullname,
               s.systemuserid
        FROM   businessunit AS b
               INNER JOIN
               systemuser AS s
               ON b.businessunitid = s.businessunitid
        WHERE  s.fullname LIKE 'XXX%') AS b_s
       ON s.systemuserid = b_s.systemuserid;

The result of this SQL should be empty, but it's not.

Thanks in advance for your support.