2013-08-28 23 views
0

UPDATEMYSQL在不同的表條件

我知道有$ id變量在TABLE_1數據的ID選擇。我在table_1和table_2中有兩個相同的列(具有相同的內容)。我想選擇並顯示table_2(結果)中的列。

表1

|  ID  |  color  | 
----------------------------------- 
     1  |  data1  |  
     2  |  data2  | 
     3  |  data3  |  
     4  |  data4  | 
     5  |  data5  |  

表2

|  ID  |  flower  |  result  | 
------------------------------------------------------ 
     11  |  data1  |  result1  |  
     12  |  data2  |  result2  |  
     13  |  data3  |  result3  |  
     14  |  data4  |  result4  |  
     15  |  data5  |  result5  |  


ID = 5
結果= result5

回答

2
Select t2.*, t1.color from t2 inner join t1 on t1.color = t2.data and t1.id = '$id' 
0

一個簡單的聯接將處理這個問題。

select t2.result 
from table1 t1 
join table2 t2 
on t1.color = t2.flower 
where t1.id = 5 
0

SELECT result FROM t2 JOIN t1 ON (t1.color = t2.data AND t1.id = $id);

0

你需要有一些共同點與tabels ... 例 表1:都會有標識和顏色 表2:將有ID,ID_table1,花,導致

然後U可以這樣做:

$select1=mysql_query("select * from table1"); 
$id_table1=mysql_result($select1,0,'enter the id here'); 
$select2=mysql_query("select * from table2 where ID_table1='".$id_table1."'"); 
$result=mysql_result($select2,0,'result');