การ SELECT (ซีเล็คท์) ข้อมูลบางคอลัมน์จากหลายตาราง
โค้ด :
SELECT product_product.product_tmpl_id, product_template.id,
product_template.categ_id,product_category.id,
product_product.name_template,product_category.name
FROM product_template
LEFT JOIN product_product
ON product_template.id = product_product.product_tmpl_id
LEFT JOIN product_category
ON product_template.categ_id = product_category.id
ORDER BY product_template.id;
ผลที่ได้ :
คำอธิบาย :
การ SELECT (ซีเล็คท์) หลายตารางร่วมกันเป็นการดึงข้อมูลที่อยู่คนละตารางแต่มีความสัมพันธ์กันมาแสดง ให้เห็นถึงข้อมูลของ Products (โปรดักส์) ว่า product แต่ละตัวอยู่ใน category (แคท-อิโกริ) ไหน
โดยใช้คำสั่ง
LEFT JOIN table
ON conditions
สามารถศึกษาเพิ่มเติมได้ที่ คำสั่ง SQL ต่างๆ
www.postgresqltutorial.com Eng.ver
www.postgresql.org Eng.ver
โดย : http://www.mindphp.com