I have the following Select statement, but want to change it to use iner joins as I believe they are more efficient, but not too sure where to start.
我有以下Select语句,但想要将其更改为使用iner连接,因为我相信它们更有效,但不太确定从哪里开始。
DECLARE @myNameID int
DECLARE @myAddressID int
DECLARE @myFirstName nvarchar(256)
SET @myNameID = 1
SET @myAddressID =1
SET @myFirstName='Nathan'
SELECT @myNameID = myNameID
FROM
NameTable Name,
AddressTable Address,
CountryTable Country
WHERE
Name.[FirstName] = @ myFirstName and
Address. AddressID = @ myAddressID and
Address.CountryID = Country.CountryID and
Name.SecondID = Country.SecondID
1 个解决方案
#1
5
SELECT @myNameID = myNameID
FROM NameTable Name
INNER JOIN CountryTable Country ON Name.SecondID = Country.SecondID
INNER JOIN AddressTable Address ON Address.CountryID = Country.CountryID
WHERE Name.[FirstName] = @myFirstName
and Address. AddressID = @myAddressID
#1
5
SELECT @myNameID = myNameID
FROM NameTable Name
INNER JOIN CountryTable Country ON Name.SecondID = Country.SecondID
INNER JOIN AddressTable Address ON Address.CountryID = Country.CountryID
WHERE Name.[FirstName] = @myFirstName
and Address. AddressID = @myAddressID