What is the difference between JOIN and UNION ?
What is the difference between JOIN and UNION ?
They combine data in different directions.
-- JOIN: one row per order, with customer columns attached
SELECT o.id, o.total, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id;
-- UNION: one list of emails from two different tables
SELECT email FROM customers
UNION
SELECT email FROM newsletter_subscribers;
| JOIN | UNION | |
|---|---|---|
| Combines | columns of related rows | rows of compatible result sets |
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.