我有以下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
答案 0 :(得分: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