SELECT pro_countid,pro_id,(SELECT pur_name FROM supplier,product WHERE pro_officeid = pur_id) AS pro_officeid
,(SELECT type_name FROM protype,product WHERE type_id = pro_typeid) AS pro_typeid
,pro_name
FROM product
Error Code : 1242
Subquery returns more than 1 row
SELECT p.pro_countid,p.pro_id,
(SELECT x.pur_name FROM supplier x WHERE p.pro_officeid = x.pur_id) AS pur_name,
(SELECT x.type_name FROM protype x WHERE x.type_id = p.pro_typeid) AS type_name,
p.pro_name
FROM product As p
แต่เขียนแบบนี้อ่านง่ายกว่าครับ Code
SELECT p.pro_countid, p.pro_id,
sp.pur_name, pt.type_name,
,p.pro_name
FROM product As p
LEFT JOIN supplier AS sp ON p.pro_officeid = sp.pur_id
LEFT JOIN protype AS pt ON p.pro_typeid = x.type_id
ขอบคุณทุกท่านมากๆครับ
ได้แล้วครับผมสับสนไปเอง ไปมั่ว sub query ตั้งนาน
Code
SELECT pro_countid,pro_id,pur_name
,type_name
,pro_name
FROM product,supplier,protype
WHERE product.pro_officeid = supplier.pur_id
AND protype.type_id = product.pro_typeid
ORDER BY(pro_countid) ASC