Inner Join Syntax

  • Hi All,

    Please help me in the sysntaxt of Inner join. I want to pull the data from multiple table (5 tables) using Join on the particular key. So, please help me in this issue.. its an urgent for me...

    I will appreciate for your help...

    Regards,

    KP

  • hi !

    You seems to be really new in Database. you can check on BOL for inner join syntax. but for your reference here is the syntax for Inner Join..

    Select (either from table 1 Or table 2 )

    From table1

    INNER JOIN table2 table1.KeyID = table2.RefKeyID ( from table1)

  • If you're writting your syntax properly and not coming up with the result set you expect, there could be one of two problems.

    1) You're using the wrong keys to join tables on

    or

    2) You started off with the wrong table.

    Usually I start off with the biggest table or the table likely to have the most matching records. Think of INNER JOIN for more than 2 tables like a pyramid. Each JOIN (if done correctly) is going to narrow down the record set.

    If not done correctly, you could potentially end up with multiple rows that are almost duplicates of each other.

    Search the BOL Index for subjects "inner joins [SQL Server]" and "joins [SQL Server]". You'll want to understand all the JOIN types before you do any joining. This way you can properly troubleshoot any problems you're having with the JOIN operator.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • I think this is very basic question. so do a search in google.

    karthik

  • Thanks to you all,

    Regards,

    KP

  • Suppose we have three tables

    Employee(Emp_code,Name,Dept_Code,Desig_Code,CityID)

    Department(Dept_Code,Dept_Name)

    Designation(Desig_Code,DesigName)

    City(CityID,CityName)

    Query :

    Select Emp_code,Name,Dept_Name,DesigName,CityName from Employee inner join Department On Department.Dept_Code=Employee.Dept_Code inner join

    Designation ON Designation.Desig_Code=Employee.Desig_Code inner join City ON City.CityID=Employee.CityID

    Same for other table

  • Please note: 8 year old thread.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply