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.
It works correctly if you use different alias names for the main query and subquery.
I get the below error If I remove b.businessunitid in the subquery:
The result of this SQL should be empty, but it's not.
b.businessunitid
in the subquery:Thanks in advance for your support.