Вот простой пример, который вы можете запустить в SSMS:
DECLARE @Accounts TABLE ( AccountID INT, Name VARCHAR(50) );
INSERT INTO @Accounts ( AccountID, Name )
VALUES ( 1, 'Foo Bar' ), ( 2, 'Jon Dow' );
DECLARE @Addresses TABLE ( AccountID INT, AddressLine VARCHAR(50), City VARCHAR(50) );
INSERT INTO @Addresses ( AccountID, AddressLine, City )
VALUES ( 1, '123 Test Rd', 'New York' ), ( 1, '456 Test Rd', 'New York' ), ( 2, 'Lombard Street', 'San Francisco' ), ( 2, 'Lombard Street', 'San Francisco' );
SELECT
Accounts.AccountID,
AddressRecords.AddressLine,
Addresses.City
FROM @Accounts AS Accounts
INNER JOIN @Addresses AS Addresses
ON Accounts.AccountID = Addresses.AccountID
OUTER APPLY (
SELECT CASE
WHEN ( SELECT COUNT ( DISTINCT ( x.AddressLine ) ) FROM @Addresses AS x WHERE x.AccountID = Accounts.AccountID ) > 1 THEN 'Multiple'
ELSE ( SELECT DISTINCT AddressLine FROM @Addresses AS x WHERE x.AccountID = Accounts.AccountID )
END AS AddressLine
) AS AddressRecords
WHERE
Accounts.AccountID = 1
GROUP BY
Accounts.AccountID, AddressRecords.AddressLine, Addresses.City;
AccountID 1 RETURNS
+-----------+-------------+----------+
| AccountID | AddressLine | City |
+-----------+-------------+----------+
| 1 | Multiple | New York |
+-----------+-------------+----------+
AccountID 2 RETURNS
+-----------+----------------+---------------+
| AccountID | AddressLine | City |
+-----------+----------------+---------------+
| 2 | Lombard Street | San Francisco |
+-----------+----------------+---------------+
Конечно , это не учитывает возможность нескольких значений города.