Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    176

    Querying tables from different databases on same sql server

    Hi all,

    How do I query two tables in different databases on the same SQL Server?

    In short, I want to do:

    Select A.*
    from database 1. table 1 as A
    inner join database 2. table 1 as B
    on A.COL1 = B.COL1

    Both database 1 and 2 are on the same SQL Server.

    Please advise.

    Thanks,

    V

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,564
    You just need to fully qualify the object names:

    select * from Database.Owner.Table

    ...but the owner is assumed to be dbo if omitted, so this works most of the time:

    select * from Database..Table
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Aug 2006
    Location
    San Francisco, CA
    Posts
    136
    Huh...I didn't know this. I guess you learn something new everyday.

    Thanks blindman

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    14,902
    Quote Originally Posted by Reghardt
    Huh...I didn't know this. I guess you learn something new everyday.
    Pretty much any day that is worth getting out of bed anyway!

    -PatP

  5. #5
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    you also forget something every day. trick is to forget the useless stuff.

Posting Permissions

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