 |
ผมขอตัวอย่าง การ select ซ้อน select มี่ท่านใดพอแนะนำ หรือ ให้ตัวอย่างได้ หรือเปล่า ครับ |
|
 |
|
|
 |
 |
|
ยังไงครับ ลองอธิบายเพิ่มเติมครับ
|
 |
 |
 |
 |
Date :
2013-03-23 10:59:55 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (SQL)
select *
from table1
where table1.id
in (
select table2.id from table2
)
|
 |
 |
 |
 |
Date :
2013-03-23 12:55:40 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นการ select ตารางเดียวแต่ 2 ครั้ง
ผมดูตัวอย่างจากในเว็บนี้มาครับ เอามา ปรับใช้เอา แต่ พอรันหน้าเว็บรันไม่ออก
แต่ เอาไปรัน ใน phpMyadmin ออก ครับ
Code (PHP)
$rs_group = mysql_query("SELECT count(order_generation) AS V_TOTAL1 , SUM(size_new) AS V_TOTAL , check_status , order_ID ,order_generation AS V_TOTAL2 FROM genneration_size
WHERE check_status='0' or check_status='1' or check_status='2' AND order_generation IN ('ASD', 'CSD', 'HRG', 'LBG', 'LSD', 'OBD', 'PFR', 'RAL', 'WSG', '$hdata')
GROUP BY order_generation");
while($row_group = mysql_fetch_array($rs_group))
{
$rs_menu = mysql_query("SELECT count(order_generation) AS V_TOTAL_new1 , SUM(size_new) AS V_TOTAL_new , check_status , order_ID ,order_generation AS V_TOTAL2_ FROM genneration_size WHERE check_status='0' or check_status='1' AND order_generation='$V_result3' AND order_generation IN ('ASD', 'CSD', 'HRG', 'LBG', 'LSD', 'OBD', 'PFR', 'RAL', 'WSG', '$hdata') AND order_generation = ".$row_group['order_generation']."
GROUP BY order_generation");
while($row_menu = mysql_fetch_array($rs_menu))
{
echo $row_menu['order_generation'];
}
}
|
ประวัติการแก้ไข 2013-03-23 15:13:11
 |
 |
 |
 |
Date :
2013-03-23 15:10:46 |
By :
TonsoR |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ไม่ยากนี่ครับ จากตัวอย่าง แค่เป็นการคิวรีตารางรอบที่ 1 แล้วนำค่าที่ได้จากการคิวรีรอบแรกมาคิวรีในรอบที่ 2 โดยที่ยังคิวรีตารางเดิม
ถ้ายังงงอยู๋ให้ลองดูด้วยโค้ดง่ายๆ อ่ะครับ
แล้วก็ลองแก้ตรง
Code (PHP)
AND order_generation = ".$row_group['order_generation']."
เป็น
Code (PHP)
AND order_generation = '".$row_group['order_generation']."'
ลองดูนะครับ เพื่อได้
|
 |
 |
 |
 |
Date :
2013-03-23 17:22:32 |
By :
akkaneetha |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|