Results 1 to 3 of 3

Thread: Inner Join Alias syntax SQL query question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Inner Join Alias syntax SQL query question

    Hello:

    I would like to compare two database tables. Somehow, I am supposed to use aliases here, however I have no idea how this is done.

    Query below:
    Code:
    SELECT ACME.dbo.documents.filename, ACME.dbo.documents.LatestRevisionNo, ACME.dbo.documents.WorkingVersionModified, ACME2.dbo.documents.filename, ACME2.dbo.documents.LatestRevisionNo, ACME2.dbo.documents.WorkingVersionModified FROM ACME.dbo.Documents
    INNER JOIN ACME2.dbo.documents
    ON ACME.dbo.documents.filename = ACME2.dbo.documents.filename
    Thanks in advance!

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Inner Join Alias syntax SQL query question

    After the name of the table in the FROM clause you can specify the alias, eg:
    Code:
    FROM ACME.dbo.Documents  AS Doc1
    INNER JOIN ACME2.dbo.documents AS Doc2
    (you may not need the keyword AS, but I think it helps with clarity)

    Then you use the alias in the rest of the query, instead of the table name, so it becomes:
    Code:
    SELECT Doc1.filename, Doc1.LatestRevisionNo, Doc1.WorkingVersionModified, 
           Doc2.filename, Doc2.LatestRevisionNo, Doc2.WorkingVersionModified 
    FROM ACME.dbo.Documents  AS Doc1
    INNER JOIN ACME2.dbo.documents AS Doc2
       ON Doc1.filename = Doc2.filename

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: Inner Join Alias syntax SQL query question

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width