Skip to content · ⁨ข้ามไปยังเนื้อหา⁩
English

Joining two tables

To use data from both tables at once, you join them. An INNER JOIN pairs up rows that match on a key — here, the order's customer_id with the customer's id:

When a column name could come from either table, write table.column so it is clear.

ไทย

การเชื่อมสองตาราง

เพื่อใช้ข้อมูลจาก ทั้งสอง ตารางพร้อมกัน คุณต้อง เชื่อมต่อ它们 An INNER JOIN จับคู่แถวที่ตรงกันตามคีย์ — ที่นี่คือ customer_id ของคำสั่งซื้อกับ id ของลูกค้า:

SELECT customer.name, orders.total
FROM customer
INNER JOIN orders ON customer.id = orders.customer_id;

เมื่อชื่อบริการสามารถมาจากตารางใดก็ได้ ให้เขียน table.column เพื่อให้ชัดเจน

Handout · ⁨เอกสารประกอบการเรียน⁩

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP