我有兩個表具有這種結構的結果是:PHP比較兩個表
表之一: ID說明
表二: ID名稱
我要呼應只有兩者的ID的表,但我不知道如何比較。
if($id is in the first table AND $id is in the second table){
echo $id;
echo $description;
echo $name
}
如何做到這一點: 我可以用一個愚蠢的例子證明我的想法? 謝謝!
我有兩個表具有這種結構的結果是:PHP比較兩個表
表之一: ID說明
表二: ID名稱
我要呼應只有兩者的ID的表,但我不知道如何比較。
if($id is in the first table AND $id is in the second table){
echo $id;
echo $description;
echo $name
}
如何做到這一點: 我可以用一個愚蠢的例子證明我的想法? 謝謝!
$sql = mysql_query("SELECT t1.*,t2.* FROM table1 as t1, table2 as t2 WHERE t1.id=t2.id AND t1.id='$id'")
while($data = mysql_fetch_array($sql)){
echo $data["id"];
echo $data["description"];
echo $data["name"];
}
嗨mgraph,謝謝! – 2012-02-04 12:17:31
試試下面
select one.id from myTableOne one, myTableTwo two WHERE one.id=two.id
這將給中存在兩個表中的ID列表...
好運!
嗨@fahim,非常感謝! – 2012-02-04 12:17:46
歡迎..高興地幫助:) :) – 2012-02-04 12:26:01
使用此查詢,
SELECT
T1.ID,
T1.Description,
T2.Name
FROM
`TableOne` AS `T1`
INNER JOIN
`TableTwo` AS `T2`
ON
(T1.ID=T2.ID)
你有什麼數據庫? MYSQL或Oracle? – 2012-02-04 12:02:24
看到我的答案... – 2012-02-04 12:07:48