SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    query between 2 databases

    hi,i would like to make a query between 2 databases

    eg.

    PHP Code:
    select memberID from databaseA.table1
    $id
    =$row['memberID']
    select address from databseB.table2 where memberID='".$id."' 
    may i know how will the connection among these 2 databases work and how can i perform the query?

    thank you!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select two.address
      from databaseA.table1 as one
    inner
      join databaseB.table2 as two
        on two.memberID = one.memberID
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Code:
    select two.address
      from databaseA.table1 as one
    inner
      join databaseB.table2 as two
        on two.memberID = one.memberID
    thanks you, r937!

    what about the database connection?
    is it just connect each database as usual?

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you can connect to either database. it's not possible to connect to both at the same time. because you explicitly tell mysql which database to use, there is no need to specify both in the connection.

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    you can connect to either database. it's not possible to connect to both at the same time. because you explicitly tell mysql which database to use, there is no need to specify both in the connection.
    oh i see...
    thanks again, longneck...


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
  •