合并SQL结果

时间:2015-03-20 09:37:14

标签: php sql sql-server

我必须运行两个单独的SQL查询,因为数据库位于不同的服务器上:

$link1 = mssql_connect($server1, $SQLUser1, $SQLPass1);
$link2 = mssql_connect($server2, $SQLUser2, $SQLPass2);
$db_Query1 = "SELECT col1, col2, col3, col4, col5, col6
              FROM table;";
$db_Query1 = "SELECT col1, col2, col3, col4, col5, col6
              FROM table;";
$result_id1 = mssql_query($db_Query1, $link1);
$result_id2 = mssql_query($db_Query2, $link2);

所以此时我需要合并$result_id1$result_id2

1 个答案:

答案 0 :(得分:0)

如果您想合并,可以使用:

merge tableB targetTable
using tableA sourceTable
on sourceTable.IsReady = 1 and [any other condition]
when not matched then
insert ...
when matched and [...] then
update ...