Member-only story
SET vs. JOIN in SQL
UNION , UNION ALL စတဲ့ SET Operations တွေကို ဘယ်အချိန်မှာ သုံးပြီး
INNER / OUTER စတဲ့ Join Operation တွေကို ဘယ်အချိန်မှာ သုံးရတာပါလဲ?
SET Operations (UNION, UNION ALL)
- When to use: Use
UNIONorUNION ALLto combine rows from two or more queries (i.e., results of two separateSELECTstatements) into a single result set. The tables involved should have the same structure (same number of columns and data types), but they don’t need to be related by a key or condition.
SELECT name FROM table1
UNION
SELECT name FROM table2;SET ကို Query — ၂ ခုက ရတဲ့ ရလဒ်တွေကို ပေါင်းစည်းချင်တဲ့အခါ အသုံးပြုပါတယ်။ ဒီနေရာမှာ သတိထားရမှာက data type အမျိုးအစားတူရမှာ ဖြစ်ပါတယ်။
JOIN Operations (INNER JOIN, LEFT JOIN, etc.)
- When to use: Use
JOINto combine related data from two or more tables based on a condition, typically a common column between the tables (e.g., a foreign key relationship).
SELECT employees.name, departments.name
FROM employees
INNER JOIN departments ON employees.dept_id = departments.id;Refer here for more details on JOIN.









