如何将此T-SQL查询转换为使用显式连接语法?

时间:2009-10-05 12:45:54

标签: sql sql-server sql-server-2005 tsql

我有以下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 个答案:

答案 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