Select tb_order.*,(select count(*) from tb_order_detail where tb_order_detail.or_detail_status = 'W' GROUP BY tb_order_detail.or_id) as total,
tb_user.nameuser,tb_user.surname,tb_department.dep_name
From tb_order
INNER JOIN tb_order_detail ON tb_order.or_id=tb_order_detail.or_id
INNER JOIN tb_user ON tb_order.or_user_id=tb_user.iduser
INNER JOIN tb_department ON tb_user.depid=tb_department.dep_id
Where tb_order.or_status='W'
GROUP BY or_id,or_user_id
"อย่างที่ commet แรกบอกอะ
ไม่ให้ใส่ group by ครับ
มันจะ return มาหลาย Row
มันเลย error
อันนี้ แก้แบบไม่รู้ schema นะ
เปลี่ยนจาก GROUP BY tb_order_detail.or_id เป็น AND tb_order_detail.or_id = tb_order.or_id"
***********************************
Code
Select tb_order.*,(select count(*) from tb_order_detail where tb_order_detail.or_detail_status = 'W' and tb_order_detail.or_id=tb_order.or_id) as total,
tb_user.nameuser,tb_user.surname,tb_department.dep_name
From tb_order
INNER JOIN tb_order_detail ON tb_order.or_id=tb_order_detail.or_id
INNER JOIN tb_user ON tb_order.or_user_id=tb_user.iduser
INNER JOIN tb_department ON tb_user.depid=tb_department.dep_id
Where tb_order.or_status='W'
GROUP BY or_id,or_user_id