👁 0
Q: Explain the difference between INNER JOIN and LEFT OUTER JOIN.
Answer:
INNER JOIN:
- Returns only matching rows from both tables
- If no match, row is excluded
LEFT OUTER JOIN:
- Returns all rows from left table
- Matching rows from right table
- NULL for right table if no match
-- INNER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID; -- LEFT OUTER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E LEFT OUTER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID;
Use LEFT JOIN when you want all employees even those without department.
👁 0
Q: What is the difference between INNER JOIN and LEFT OUTER JOIN?
Answer:
INNER JOIN returns only matching rows from both tables. LEFT OUTER JOIN returns all rows from left table plus matching rows from right (NULL if no match). LEFT preserves all left table rows regardless of match. INNER excludes non-matching rows from both sides.
👁 0
Q: Explain UPDATE with JOIN
Answer:
UPDATE table SET col = value FROM table t1 INNER JOIN table t2 ON... WHERE condition. Or: UPDATE t1 SET col = (SELECT col FROM t2 WHERE t2.key = t1.key). Merge statement is alternative.