Sql-server – Group by other table with sum function

sql servert-sql

I have a query that pulls in a delivered count of a campaign. Each run is a new row in the runs table. To retrieve a campaign I need to join the related table in.

SELECT c.Company, r.RunId, r.DeliveredCount FROM Run r
INNER JOIN Campaign c ON r.CampaignId = c.Id
WHERE r.RunId = 3001626 AND c.Company LIKE '%74108%'

Why does it return more than one row, even when I specify the Run Id I would like to pull?

Best Answer

Try this

select * 
from Campaign  
where CampaignId = 3001626 
AND Company LIKE '%74108%'

I suspect you will get more than one row