|
 |
|
มีข้อมูลสองเทเบิลค่ะ จะเอาข้อมูลจาก www.bb มาใส่ใน rrr.bb โดยที่ aa ทั้งสองตารางตรงกันนะค่ะ จะเขียน sql ยังงัยค่ะ |
|
 |
|
|
 |
 |
|
rrr.bb ตอนนี้ไม่มีข้อมูลอะไรค่ะ
rrr
aa bb cc dd ee
1 null 23 5 5
2 null 34 4 44
3 null 23 33 42
4 null 23 43 55
|
 |
 |
 |
 |
Date :
2009-07-12 12:38:00 |
By :
neonai07 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้เขียนแบบนี้แต่ผลลัพท์ไม่ใช่ค่ะ
insert into rrr
(
rrr.bb
)
select
b.fff
from
(select d.aa from rrr d) a,
(select c.aa,c.bb as fff from www c) b
where a.aa= b.aa
|
 |
 |
 |
 |
Date :
2009-07-12 12:41:01 |
By :
neonai07 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่านแล้ว ผมยัง งง อยู่ครับ ลองอธิบายใหม่เอาแบบละเอียดครับ
|
 |
 |
 |
 |
Date :
2009-07-13 09:03:32 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
table rrr
aa bb cc dd ee
1 23 5 5
2 34 4 44
3 23 33 42
4 23 43 55
table www
aa bb
1 gggg
2 ttttttttt
3 yyyyyyy
select rrr.aa,rrr.bb,www.bb as bb2,rrr.cc,rrr.dd,rrr.ee
from rrr
left outer join www
on rrr.aa = www.aa
ข้อมูลที่ได้
aa bb bb2 cc dd ee
1 23 gggg 5 5
2 34 ttttttttt 4 44
3 23 yyyyyyy 33 42
4 23 null 43 55
|
 |
 |
 |
 |
Date :
2009-07-13 09:08:48 |
By :
taobsd |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าตามที่ผมเข้าใจ คือ จะ update ตารางโดย เอา ข้อมูลจากตาราง
table www มาใส่ใน table rrr ประมาณนี้ใช้ไหมครับ
ถ้าใช่เราสั่ง update ก็ได้นี้ครับ โดยให้ คิวรี่ข้อมูลจาก table www มาแล้ว replace ลงในตาราง rrr โดยใช้เงื่อนใข ให้ เช็คที่ ช่อง aa ว่าเหมือนกันหรือไม่ ใช่ไหมครับ
Code (PHP)
<?php
// สั่งคิวรี้ตาราง www
$sql="select * form table www ";
$dbquery = mysql_db_query($db, $sql);
$num_rows = mysql_num_rows($dbquery);
$i=0;
while ($i<$num_rows)
{
$rs=mysql_fetch_array(dbquery);
$bb=$rs[bb];
$aa=$rs[aa];
// สั่งอับเดทข้อมูลลงในตาราง rrr
$sqlrrr="update tablerrr set bb='$bb' where aa='$aa' ";
$query = mysql_db_query($db, $sqlrrr);
$i++;
}
?>
|
 |
 |
 |
 |
Date :
2009-07-13 09:34:20 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุค่ะได้แล้วค่ะ
|
 |
 |
 |
 |
Date :
2009-07-15 20:18:58 |
By :
neonai07 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เจ่งจริง
|
 |
 |
 |
 |
Date :
2009-07-16 11:05:01 |
By :
o1n2c3b4 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
good
|
 |
 |
 |
 |
Date :
2009-07-16 11:12:09 |
By :
survey007 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|