สอบถามเรื่อง sub คิวรี่ ครับ

อยากทราบว่า sub คิวรี่ แบบใหนไวกว่ากันครับ
:::::::::แบบที่ 1:::::::::::::::
select
 a.id,
(select count(b.id)from [table2] as b where   a.id = b.id) as count1,
(select count(c.id)from [table3] as c where   a.id = c.id) as count2
from
[table1] as a

::::::::กับ แบบที่ 2::::::::::::::
$sql = "select  id from [table1] as a"
$query = $db->query($sql);
while($rec = $db->db_fetch_array($query)){
 (select count(b.id)from [table2] as b where  $rec['id'] = b.id);
 (select count(c.id)from [table2] as c where  $rec['id'] = c.id) ;
}

แบบใหนทำงานไวกว่ากันครับ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่