views:

93

answers:

1

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.

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
+5  A: 
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
Andrew
Thanks...I'm just starting to get the hang of SQL!!
Gribbler
The only thing I would change about Andrew's solution, and the original query, is the use of the word Name as an alias for NameTable. While it will work fine, I tend to try to reduce possible confusion by not using reserved words as aliases or table names.
BBlake
Cool, the table name isnt really name, ive just tried to make the names easier to relate to.
Gribbler
i think you want to do SELECT myNameID= @myNameID ??
anishmarokey