0

I have two databases, one with a table called v_esd and the other call channel_did

in v_esd there is a column called number and in channel_did a column called did

i want to search through the channel_did table and match the did column value with the number column in the v_esd table. if there is no match, display the results.

i have 2 different connection strings as they are 2 completely separate databases

charlie
  • 1,356
  • 7
  • 38
  • 76

2 Answers2

0

try this:

SELECT * FROM `database1`.`v_esd` JOIN `database2`.`channel_did` ON `database1`.`v_esd`.`number` = `database2`.`channel_did`.`did`

this should work, maybe you can shorten this Statement by using 'AS' in the query

Sirac
  • 693
  • 4
  • 18
  • i am using a connection string like $conn=mysql_connect("localhost","user","pass"); mysql_select_db("db_name",$conn); so i have two of these, the second one is not called $conn so how does it know what to connect to when running the SQL Query? – charlie Oct 31 '13 at 20:20
  • do you mean, you have two mysql-connections or two databases? (by the way i would use the mysqli-functions instead of the mysql-functions, they are newer and work better) – Sirac Oct 31 '13 at 20:25
0
SELECT * FROM db1.channel_did.did WHERE did NOT IN(SELECT number FROM db2.v_esd )

Just drop the select db statement,and if they are on the same server your connection will be able to access any db on that server. Nope,no possibility to do that in one query,if they are on separate server.

$rs = mysql_query($query1);

    while($row1 = mysql_fetch_assoc($rs)) {
      if($i<$numrows){
        $data1[$i] = $row1;
    }
  }

$rs2 = mysql_query($query2);
    while($row2 = mysql_fetch_assoc($rs2)) {
      if($i<$numrows){
        $data2[$i] = $row2;
    }
  }
$uniquevalues = array_merge(array_diff($row1, $row2), array_diff($row2, $row1))

Something like this

Mihai
  • 26,325
  • 7
  • 66
  • 81