Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Using same SQL table twice in one query with different contexts. Help please.

$
0
0

I'm tying myself in knots over something I'm sure is very simple.

I'm building a query that needs to extract info from the same column but in two separate contexts. Here's the query so far:

Text
SELECT [stra_Deleted] ,[stra_Secterr] ,[stra_Name] ,[stra_Status] ,[company].[Comp_Name] AS Stra_Comp ,[stra_Ref] ,[Opportunity].[Oppo_TargetClose] ,[company].[Comp_Name] AS Oppo_Comp FROM [DSN].[dbo].[Strategy] INNER JOIN [DSN].[dbo].[Company] ON stra_CompanyId = [dbo].[Company].Comp_CompanyId INNER JOIN [DSN].[dbo].[Opportunity] ON stra_StrategyID = [Oppo_StrategyId] 

I now need to join the Company table again as companies are linked to opportunities as well as strategies and I need to select the company associated with each opportunity as well as the strategy company.

I have tried joining the Company table a second time on oppo_companyID =...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>