Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Posts
    4

    Unanswered: Syntax for table join

    Is there a way to join 2 tables from different databases on the same instance? If so, what is the syntax? For example I have an instance called TEST with 2 databases (DB1 and DB2). Each database have a table (DB1.TABLE & DB2.TABLE). Both tables have a common column called ID.
    Can both tables be joined in a query?

    TIA.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Can you post the assignment exactly as the instructor or TA gave it to you?

    -PatP

  3. #3
    Join Date
    May 2006
    Posts
    4
    I think I've found the answer. A search turned up this:

    select *
    from MyDB.dbo.MyTable a
    join YourDB.dbo.YourTable b
    on a.KeyColumn = b.KeyColumn
    where blah, blah, blah

    I will try it to see if it works.
    Thanks.

  4. #4
    Join Date
    May 2006
    Posts
    4
    Yep, that worked.

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Good job. By the way, welcome to the forum!

    -PatP

  6. #6
    Join Date
    May 2006
    Posts
    4
    Thanks Pat.

    Clint.

Posting Permissions

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