SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT Query across multiple databases

    Okay, I'm using Microsoft SQL Server 7.0. I have a database repository of Users that I want to be used by multiple sites. However, today I realized that some tables from the databases for the other sites need to link by UserID to the repository database. For example, I need to get a list of documents posted by particular users. I know that if they were in the same database I could just do:
    SELECT * FROM Documents D INNER JOIN Users U ON U.UserID = D.UserID
    Is there a way to do this by specifying the database? Or do I have to do something else.

    Thank you,
    Joe Fiorini
    -Joe

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    This should work:

    Code:
    SELECT field1, field2, etc
      FROM dataserver.database.dbo.tablename1, 
           tablename2
     WHERE tablename1.field3 = tablename2.field3
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2002
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm a moron

    Yeah, I should have thought of that. Oh well, thanks a lot! That helped a lot!

    -Joe
    -Joe

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    no problem...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how 'bout
    select * from table1 a join differentDB..table2 b on b.field1 = a.field3

    ??
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  6. #6
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by spartan
    how 'bout
    select * from table1 a join differentDB..table2 b on b.field1 = a.field3

    ??
    Should do the same thing, just a different format...
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style


Bookmarks

Posting Permissions

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