I'm trying to read data out of a from a linked server and the join is bringing back only the first match. If I ran the query on the directly on the remote server I'd get multiple rows back. Both the local and remote servers are Azure Managed Instances. @@Version shows:
Microsoft SQL Azure (RTM) - 12.0.2000.8 May 15 2020 00:47:08 Copyright (C) 2019 Microsoft Corporation
The query is as follows:
DECLARE @Id INT = 15;
SELECT 'LinkedServerMI lnkSvr w/join' fromSrc, *
FROM LinkedServer.DatabaseName.dbo.CustomerInfoPhone cip
INNER JOIN dbo.CustomerInfo ci ON cip.CustomerInfoId = ci.CustomerInfoId -- Simple join
WHERE ci.CustomerInfoId = @Id; -- No other filters
-- One row comes back, expected 2 or more
SELECT 'LinkedServerMI lnkSvr select only' fromSrc, *
FROM LinkedServer.DatabaseName.dbo.CustomerInfoPhone cip
WHERE cip.CustomerInfoId = @Id;
--For the customer id in question 2 rows come back.
The Linked Server is created like so:
EXEC master.dbo.sp_addlinkedserver @server = N'LinkedServer', @srvproduct=N'SQL', @provider=N'MSOLEDBSQL', @datasrc=N'<servername>', @provstr=N'Data Source=<servername>;User ID=<remoteuser>;ApplicationIntent=ReadOnly'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'LinkedServer',@useself=N'False',@locallogin=NULL,@rmtuser='<remoteuser>',@rmtpassword='########';
Query plan was to big to share. This link should allow you to see the file hosted on Google: Linked Server Query Plan