I have the following SQL. Tables defined.
#tbContinent
--------
ContinentID | ContinentName
AddressInCountry
--------
AddressID | CountryID
AddressInContinent
--------
AddressID | ContinentID
NameInAddress
--------
AddressID | NameID
I then have the following SQL:
--- Insert into tbName
DECLARE @tbName TABLE
([ID] int, [AddressID] int, [Name] ntext)
INSERT INTO @tbName
SELECT
[Name].[NameID] AS [ID],
[Address].[AddressID],
[Name].[Name]
FROM NameInAddress INNER JOIN [Name] ON NameInAddress.NameID = Name.NameID
INNER JOIN [Address] ON NameInAddress.AddressID = Address.AddressID
WHERE [Address].[AddressID] IN
(
SELECT AddressInCountry.AddressID
FROM AddressInCountry
UNION ALL
SELECT AddressInContinent.AddressID
FROM #tbContinent AS Continent
JOIN AddressInContinent ON Continent.ContinentID = AddressInContinent.ContinentID
)
I've been asked to use joins in place of the nested select. Ive done similar ones using views to create the Union and perform joins on the view, but this one uses a temp table which I can't pass into my view so dont think that I can use the same technique.
I can't use nested selects at all.
Any ideas?