我想知道是否有人可以幫助我。SQL加入問題
我試圖合併來自兩個mySQL數據庫表的信息時出現問題。
到目前爲止,我已經放在一起的查詢如下所示。
<?php
require("phpfile.php");
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysql_connect ("hostname", $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "SELECT findid,
findosgb36lat,
findosgb36lon,
findcategory,
findname,
finddescription
FROM finds
WHERE makepublic = 'Yes'
AND sites.sitetype,
sites.sitedescription,
sites.siteosgb36lat,
sites.osgb36lon";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("findosgb36lat",$row['findosgb36lat']);
$newnode->setAttribute("findosgb36lon",$row['findosgb36lon']);
$newnode->setAttribute("findcategory",$row['findcategory']);
$newnode->setAttribute("findname",$row['findname']);
$newnode->setAttribute("finddescription",$row['finddescription']);
}
echo $dom->saveXML();
?>
我的問題是,我不知道如何把從「點」表中的所有記錄,但只有那些記錄從「查找」表,其中「makepublic」值「是」 。我已經做了一些研究,看看是否有特定的連接,即左或右的工作,但由於表之間沒有共同的字段,我知道這些不起作用。
有人可能會告訴我如何解決這個問題,請。
非常感謝
如果表格之間沒有共同的領域,你希望他們以什麼方式相互聯繫?你是否在尋找聯盟? – Jodaka
聽起來更像一個[union](http://dev.mysql.com/doc/refman/5.0/en/union.html),而不是一個連接,但沒有一個共同的列,你如何預測數據對齊? (除非我不正確理解表格的結合) –
每個表格的模式是什麼?如果它們相同或者您選擇了等效字段,則可以使用聯合。 –