{"id":496,"date":"2026-05-17T07:02:45","date_gmt":"2026-05-16T23:02:45","guid":{"rendered":"https:\/\/junai.ai\/blog\/pg-join-9\/"},"modified":"2026-05-17T07:02:45","modified_gmt":"2026-05-16T23:02:45","slug":"pg-join-9","status":"publish","type":"post","link":"https:\/\/junai.ai\/blog\/pg-join-9\/","title":{"rendered":"JOIN 4\uc885 \u2014 INNER\u00b7LEFT\u00b7RIGHT\u00b7FULL (\uae30\ucd08 9\ud3b8)"},"content":{"rendered":"\n<!-- WordPress REST API \ubc1c\ud589\uc6a9 HTML (\uc790\ub3d9 \uc0dd\uc131) -->\n<!-- WP-FEATURED-MEDIA-ID: 281 -->\n<div style=\"max-width:800px;margin:0 auto;\">\n<style>\n:root{--color-primary:#336791;--color-accent:#60a5fa;--color-bg:#fafafa;--color-bg-card:#ffffff;--color-text:#1e293b;--color-text-muted:#64748b;--hero-start:#0f172a;--hero-end:#336791;--font-body:-apple-system,BlinkMacSystemFont,'Apple SD Gothic Neo','Noto Sans KR',sans-serif;--size-body:17px;--line-height:1.75;}\n*{box-sizing:border-box;}\n.container{max-width:760px;margin:0 auto;padding:0 22px 80px;}\n.hero{background:linear-gradient(135deg,var(--hero-start) 0%,var(--hero-end) 100%);color:#fff;padding:72px 22px 56px;text-align:center;}\n.hero .badge{display:inline-block;background:rgba(96,165,250,0.18);color:var(--color-accent);padding:6px 14px;border-radius:999px;font-size:13px;font-weight:600;letter-spacing:0.5px;margin-bottom:18px;}\n.hero h1{margin:0 0 18px;font-size:36px;line-height:1.3;letter-spacing:-0.3px;}\n.hero p.sub{margin:0 auto;max-width:580px;font-size:17px;color:#bfdbfe;}\n.hero img{width:100%;max-width:720px;height:auto;margin:36px auto 0;display:block;border-radius:10px;box-shadow:0 8px 32px rgba(0,0,0,0.3);}\n.meta{display:flex;gap:14px;justify-content:center;margin-top:20px;font-size:13px;color:#93c5fd;flex-wrap:wrap;}\n.meta span::before{content:\"\u00b7\";margin-right:14px;color:#1e3a8a;}\n.meta span:first-child::before{content:\"\";margin:0;}\narticle{background:var(--color-bg-card);margin-top:-36px;padding:44px 28px;border-radius:14px;box-shadow:0 2px 18px rgba(0,0,0,0.06);}\narticle p{margin:0 0 18px;}\nh2{font-size:28px;line-height:1.35;letter-spacing:-0.3px;margin:48px 0 18px;padding-bottom:10px;border-bottom:2px solid var(--color-primary);}\nh2:first-of-type{margin-top:8px;}\nh3{font-size:21px;line-height:1.4;margin:30px 0 12px;color:var(--color-primary);}\ncode{background:#f1f5f9;color:#0f172a;padding:2px 6px;border-radius:4px;font-family:'SFMono-Regular',Menlo,Consolas,monospace;font-size:0.92em;}\npre{background:#0f172a;color:#e2e8f0;padding:18px 20px;border-radius:10px;overflow-x:auto;font-size:14.5px;line-height:1.65;margin:18px 0;}\npre code{background:transparent;color:inherit;padding:0;}\nul,ol{margin:0 0 18px;padding-left:24px;}\nli{margin-bottom:8px;}\nstrong{color:#0f172a;}\n.databox{background:#eff6ff;border-left:4px solid var(--color-primary);padding:18px 20px;border-radius:6px;margin:22px 0;}\n.databox p{margin:0 0 8px;}\n.databox p:last-child{margin:0;}\n.databox strong{color:var(--color-primary);}\n.warnbox{background:linear-gradient(135deg,#fef3c7 0%,#fde68a 100%);border-left:4px solid #d97706;padding:18px 20px;border-radius:6px;margin:22px 0;}\n.warnbox strong{color:#92400e;}\n.tablewrap{overflow-x:auto;-webkit-overflow-scrolling:touch;margin:22px 0;}\ntable{width:100%;border-collapse:collapse;font-size:15px;background:var(--color-bg-card);}\nth,td{padding:11px 12px;text-align:left;border-bottom:1px solid #e2e8f0;vertical-align:top;}\nth{background:#f1f5f9;font-weight:700;color:#0f172a;}\ntd:first-child,th:first-child{font-weight:700;}\n.cta{background:linear-gradient(135deg,#336791 0%,#60a5fa 100%);color:#fff;padding:30px 24px;border-radius:12px;margin-top:44px;text-align:center;}\n.cta h3{color:#fff;margin:0 0 10px;}\n.cta p{margin:0;color:#dbeafe;}\n.series-nav{background:#eff6ff;padding:18px 22px;border-radius:10px;margin-top:24px;font-size:14.5px;color:var(--color-text-muted);}\n.series-nav strong{color:var(--color-primary);}\n@media (max-width:480px){.hero{padding:52px 18px 44px;}.hero h1{font-size:26px;}.hero p.sub{font-size:15px;}article{padding:28px 18px;border-radius:10px;}h2{font-size:22px;}h3{font-size:18px;}body{font-size:16px;}pre{font-size:13px;padding:14px 16px;}}\n@media (max-width:560px){.tablewrap table,.tablewrap thead,.tablewrap tbody,.tablewrap tr,.tablewrap th,.tablewrap td{display:block;width:auto;}.tablewrap thead{display:none;}.tablewrap tr{margin:0 0 14px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden;}.tablewrap td{border:none;border-bottom:1px solid #f1f5f9;padding:9px 14px;}.tablewrap td:first-child{background:#eff6ff;font-weight:800;font-size:15.5px;}.tablewrap td:last-child{border-bottom:none;}.tablewrap td[data-label]::before{content:attr(data-label) \" \u2014 \";font-weight:700;color:var(--color-primary);}}\n<\/style>\n<header class=\"hero\">\n  <span class=\"badge\">PostgreSQL \uad50\uc7ac \u00b7 9\ud3b8 \/ 24\ud3b8<\/span>\n  <h1>JOIN 4\uc885 \u2014 INNER\u00b7LEFT\u00b7RIGHT\u00b7FULL<\/h1>\n  <p class=\"sub\">\uad00\uacc4\ud615 DB \uc758 \uc9c4\uac00. 4\uc885 JOIN \uadf8\ub9bc \ube44\uad50\uc640 \uce74\ud2f0\uc2dc\uc548 \uacf1\uc758 \ud568\uc815.<\/p>\n  <div class=\"meta\"><span>SQL \uae30\ucd08<\/span><span>\uc77d\ub294 \uc2dc\uac04 8\ubd84<\/span><span>2026-05-17<\/span><\/div>\n  <img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/hero-60.jpg\" alt=\"INNER LEFT RIGHT FULL JOIN \uc758 \ubca4 \ub2e4\uc774\uc5b4\uadf8\ub7a8\uc774 4\uac1c\ub85c \ube44\uad50\ub41c \ub3c4\uc2dd\">\n<\/header>\n\n<div class=\"container\">\n<article>\n\n<p>\uad00\uacc4\ud615 DB \uc758 &#8220;\uad00\uacc4&#8221; \uac00 \uc0b4\uc544\ub098\ub294 \uc21c\uac04\uc774 JOIN \uc785\ub2c8\ub2e4. \ub450 \ud14c\uc774\ube14\uc744 \uacf5\ud1b5 \ud0a4\ub85c \uc5f0\uacb0\ud574 \ud55c \uacb0\uacfc\ub85c \u2014 \uc774\uac8c \uc548 \ub418\uba74 \ub9e4\ubc88 N+1 \ucffc\ub9ac \uc9c0\uc625. 9\ud3b8\uc740 4\uac00\uc9c0 JOIN \uc758 \ucc28\uc774\ub97c \uadf8\ub9bc\uacfc \uc608\uc81c\ub85c \uc815\ud655\ud788 \ubcf4\uace0, \uac00\uc7a5 \ud754\ud55c \uc0ac\uace0 <strong>\uce74\ud2f0\uc2dc\uc548 \uacf1<\/strong> \ub3c4 \uc815\ub9ac\ud569\ub2c8\ub2e4.<\/p>\n\n<p>\uc2e4\uc2b5 \ud14c\uc774\ube14 \u2014 \uc0ac\uc6a9\uc790\uc640 \uc8fc\ubb38:<\/p>\n\n<pre><code>users          orders\n\u2500\u2500\u2500\u2500\u2500          \u2500\u2500\u2500\u2500\u2500\u2500\nid name        id user_id total\n 1 \uc900\uc131         1     1   10000\n 2 \ud64d\uae38\ub3d9       2     1    5000\n 3 \uae40\uc790\ubc14       3     2   30000\n                4    99   99000   \u2190 \uace0\uc544 \ub370\uc774\ud130(\uc5c6\ub294 user)<\/code><\/pre>\n\n<h2>INNER JOIN \u2014 \uc591\ucabd\uc5d0 \ub2e4 \uc788\ub294 \uac83\ub9cc<\/h2>\n\n<pre><code>SELECT u.name, o.id AS order_id, o.total\nFROM   users u\nJOIN   orders o ON o.user_id = u.id;\n\n-- \uacb0\uacfc (3 \ud589) \u2014 user_id=99 \uc640 \uae40\uc790\ubc14(\uc8fc\ubb38 \uc5c6\uc74c)\ub294 \ube60\uc9d0\n-- \uc900\uc131 | 1 | 10000\n-- \uc900\uc131 | 2 |  5000\n-- \ud64d\uae38\ub3d9| 3 | 30000<\/code><\/pre>\n\n<p><code>JOIN<\/code> \ub9cc \uc4f0\uba74 INNER JOIN \uc785\ub2c8\ub2e4. \uc591\ucabd \ud14c\uc774\ube14 \ubaa8\ub450 \ub9e4\uce58\ub418\ub294 \ud589\ub9cc \uacb0\uacfc\uc5d0 \ud3ec\ud568.<\/p>\n\n<h2>LEFT JOIN \u2014 \uc67c\ucabd\uc740 \ub2e4, \uc624\ub978\ucabd\uc740 \uc788\uc73c\uba74<\/h2>\n\n<pre><code>SELECT u.name, o.id AS order_id, o.total\nFROM   users u\nLEFT JOIN orders o ON o.user_id = u.id;\n\n-- \uacb0\uacfc (4 \ud589) \u2014 \uc8fc\ubb38 \uc5c6\ub294 \uae40\uc790\ubc14\ub3c4 NULL \ub85c \ud3ec\ud568\n-- \uc900\uc131  | 1    | 10000\n-- \uc900\uc131  | 2    |  5000\n-- \ud64d\uae38\ub3d9| 3    | 30000\n-- \uae40\uc790\ubc14| NULL |  NULL  \u2190 \uc8fc\ubb38 \uc5c6\uc74c\n\n-- \"\uc8fc\ubb38\uc774 \uc5c6\ub294 \uc0ac\uc6a9\uc790\" \ucc3e\uae30 (anti-join)\nSELECT u.* FROM users u\nLEFT JOIN orders o ON o.user_id = u.id\nWHERE o.id IS NULL;<\/code><\/pre>\n\n<div class=\"databox\">\n  <p><strong>LEFT JOIN + IS NULL = anti-join.<\/strong> &#8220;\uc67c\ucabd\uc5d0\ub294 \uc788\uc9c0\ub9cc \uc624\ub978\ucabd\uc5d0\ub294 \uc5c6\ub294&#8221; \ud589\uc744 \ucc3e\ub294 \uc815\ud1b5 \ud328\ud134. <code>NOT EXISTS<\/code> \ub3c4 \uac19\uc740 \uc758\ubbf8.<\/p>\n<\/div>\n\n<h2>RIGHT JOIN \u2014 \uac70\uc758 \uc548 \uc4f4\ub2e4<\/h2>\n\n<pre><code>SELECT u.name, o.id AS order_id\nFROM   users u\nRIGHT JOIN orders o ON o.user_id = u.id;\n\n-- \uacb0\uacfc \u2014 orders \uc758 \ubaa8\ub4e0 \ud589 + users \ub9e4\uce58 (\uc5c6\uc73c\uba74 NULL)\n-- \uc900\uc131   | 1\n-- \uc900\uc131   | 2\n-- \ud64d\uae38\ub3d9 | 3\n-- NULL   | 4    \u2190 user_id=99 \ub294 users \uc5d0 \uc5c6\uc74c<\/code><\/pre>\n\n<p>RIGHT \ub294 LEFT \uc640 \uac70\uc6b8. \uac00\ub3c5\uc131 \ucc28\uc6d0\uc5d0\uc11c \uac70\uc758 \ud56d\uc0c1 LEFT \ub85c \uc801\ub294 \uac8c \ucee8\ubca4\uc158 \u2014 FROM\/JOIN \uc21c\uc11c\ub9cc \ubc14\uafb8\uba74 \ub429\ub2c8\ub2e4.<\/p>\n\n<h2>FULL OUTER JOIN \u2014 \uc591\ucabd \ub2e4 (\uc5c6\uc73c\uba74 NULL)<\/h2>\n\n<pre><code>SELECT u.name, o.id AS order_id\nFROM   users u\nFULL OUTER JOIN orders o ON o.user_id = u.id;\n\n-- \uacb0\uacfc \u2014 INNER + LEFT \ub9cc + RIGHT \ub9cc \ud569\uc9d1\ud569\n-- \uc900\uc131   | 1\n-- \uc900\uc131   | 2\n-- \ud64d\uae38\ub3d9 | 3\n-- \uae40\uc790\ubc14 | NULL    \u2190 \uc8fc\ubb38 \uc5c6\ub294 \uc0ac\uc6a9\uc790\n-- NULL   | 4       \u2190 \uc0ac\uc6a9\uc790 \uc5c6\ub294 \uc8fc\ubb38<\/code><\/pre>\n\n<p>\ub370\uc774\ud130 \ub3d9\uae30\ud654\u00b7\ucc28\uc774 \uac80\uc0ac\uc5d0\uc11c \uc4f8 \ub54c \uc788\uc9c0\ub9cc \uc77c\uc0c1 \ucffc\ub9ac\uc5d0\uc11c\ub294 \ub4dc\ubb3c\uac8c \uc0ac\uc6a9.<\/p>\n\n<h2>4\uc885 \ud55c \uadf8\ub9bc (\ud14d\uc2a4\ud2b8\ub85c)<\/h2>\n\n<div class=\"tablewrap\">\n<table>\n  <thead>\n    <tr><th>JOIN<\/th><th>\uc67c\ucabd\ub9cc<\/th><th>\uc591\ucabd \ub9e4\uce58<\/th><th>\uc624\ub978\ucabd\ub9cc<\/th><\/tr>\n  <\/thead>\n  <tbody>\n    <tr><td data-label=\"JOIN\">INNER<\/td><td data-label=\"L\">\u2717<\/td><td data-label=\"M\">\u2713<\/td><td data-label=\"R\">\u2717<\/td><\/tr>\n    <tr><td data-label=\"JOIN\">LEFT<\/td><td data-label=\"L\">\u2713 (NULL)<\/td><td data-label=\"M\">\u2713<\/td><td data-label=\"R\">\u2717<\/td><\/tr>\n    <tr><td data-label=\"JOIN\">RIGHT<\/td><td data-label=\"L\">\u2717<\/td><td data-label=\"M\">\u2713<\/td><td data-label=\"R\">\u2713 (NULL)<\/td><\/tr>\n    <tr><td data-label=\"JOIN\">FULL OUTER<\/td><td data-label=\"L\">\u2713 (NULL)<\/td><td data-label=\"M\">\u2713<\/td><td data-label=\"R\">\u2713 (NULL)<\/td><\/tr>\n  <\/tbody>\n<\/table>\n<\/div>\n\n<h2>ON vs USING \u2014 \uc870\uac74 \ud45c\uae30<\/h2>\n\n<pre><code>-- ON \u2014 \uc77c\ubc18\uc801 (\ub2e4\ub978 \uceec\ub7fc \uc774\ub984\ub07c\ub9ac\ub3c4 \uac00\ub2a5)\nJOIN orders o ON o.user_id = u.id\n\n-- USING \u2014 \uceec\ub7fc \uc774\ub984\uc774 \uac19\uc744 \ub54c\ub9cc (Postgres \uac00 \uceec\ub7fc \ud569\uccd0\uc90c)\nSELECT u.name, o.id\nFROM users u\nJOIN orders o USING (user_id);   -- u.user_id \uc640 o.user_id \uac00 \uac19\uc740 \uc774\ub984<\/code><\/pre>\n\n<h2>self-join \u2014 \uac19\uc740 \ud14c\uc774\ube14\uc744 \uc790\uae30 \uc790\uc2e0\uacfc<\/h2>\n\n<pre><code>-- \uc9c1\uc6d0-\ub9e4\ub2c8\uc800 (manager_id \uac00 \uac19\uc740 employees.id \ucc38\uc870)\nSELECT e.name AS employee, m.name AS manager\nFROM   employees e\nLEFT JOIN employees m ON m.id = e.manager_id;<\/code><\/pre>\n\n<p>\uacc4\uce35 \uad6c\uc870, \uc2dc\uac04\ucc28 \ube44\uad50(\uc5b4\uc81c vs \uc624\ub298), \uc9dd\uc9d3\uae30 \ub4f1\uc5d0\uc11c \ub4f1\uc7a5\ud569\ub2c8\ub2e4. \ubcc4\uce6d\uc774 \ud544\uc218.<\/p>\n\n<h2>\uce74\ud2f0\uc2dc\uc548 \uacf1 \u2014 \uc798\ubabb\ub41c JOIN \uc758 \ud568\uc815<\/h2>\n\n<pre><code>-- \u274c ON \uc870\uac74 \ube7c\uba39\uae30\nSELECT u.name, o.id FROM users u, orders o;\n-- \uacb0\uacfc: users.count \u00d7 orders.count = 3 \u00d7 4 = 12 \ud589\n--       \ubaa8\ub4e0 \uc870\ud569\uc774 \ub2e4 \ub098\uc634 \u2190 \uc0ac\uace0\n\n-- \u274c \uc798\ubabb\ub41c \uc870\uac74 (\uc870\uac74\uc774 \uac70\uc758 \ud56d\uc0c1 \ucc38)\nJOIN orders o ON 1 = 1\n\n-- \u2705 \ud56d\uc0c1 \ub9e4\uce6d \ud0a4 \uba85\uc2dc\nJOIN orders o ON o.user_id = u.id<\/code><\/pre>\n\n<div class=\"warnbox\">\n  <p><strong>\ub300\ub7c9 \uc0ac\uace0 1\ubc88\uc9c0.<\/strong> \uacb0\uacfc \ud589 \uc218\uac00 \uc608\uc0c1\ubcf4\ub2e4 \ud6e8\uc52c \ub9ce\uc73c\uba74 99% JOIN \uc870\uac74\uc774 \ube60\uc9c0\uac70\ub098 \uc798\ubabb\ub41c \uac83\uc785\ub2c8\ub2e4. WHERE \ucd94\uac00 \uc804\uc5d0 <code>SELECT COUNT(*)<\/code> \ub85c \ud589 \uc218\ubd80\ud130 \ud655\uc778\ud558\ub294 \uc2b5\uad00.<\/p>\n<\/div>\n\n<h2>\uc5ec\ub7ec \ud14c\uc774\ube14 \u2014 3\uac1c \uc774\uc0c1 JOIN<\/h2>\n\n<pre><code>SELECT u.name, o.id, oi.product_id, p.name AS product\nFROM   users u\nJOIN   orders o      ON o.user_id = u.id\nJOIN   order_items oi ON oi.order_id = o.id\nJOIN   products p     ON p.id = oi.product_id\nWHERE  u.id = 1;<\/code><\/pre>\n\n<p>\uc2e4\ubb34 \ucffc\ub9ac\ub294 \ubcf4\ud1b5 3-5 \uac1c \ud14c\uc774\ube14\uc744 \uc5ee\uc2b5\ub2c8\ub2e4. \ub108\ubb34 \ub9ce\uc544\uc9c0\uba74(7+ \ud14c\uc774\ube14) \ud55c \ubc88 \ub354 \uc0dd\uac01 \u2014 \ubcf4\ud1b5\uc740 \ubd84\ud574\ud574\uc11c CTE \ub610\ub294 \ubdf0\uac00 \ub354 \uae54\ub054\ud569\ub2c8\ub2e4(10\u00b713\ud3b8).<\/p>\n\n<div class=\"cta\">\n  <h3>10\ud3b8 \u2014 \uc11c\ube0c\ucffc\ub9ac\uc640 CTE(WITH)<\/h3>\n  <p>\uc911\ucca9 SELECT \uc640 \uac00\ub3c5\uc131 \uc88b\uc740 WITH \uc808. \uc7ac\uadc0 CTE \ud55c \uc904\uae4c\uc9c0.<\/p>\n<\/div>\n\n<div class=\"series-nav\">\n  <strong>\ud83d\udcda PostgreSQL \ubc30\uc6b0\uae30 \uad50\uc7ac<\/strong><br>\n  \uc774\uc804: 8\ud3b8 GROUP BY \u00b7 \ud604\uc7ac: <strong>9\ud3b8 (SQL \uae30\ucd08)<\/strong> \u00b7 \ub2e4\uc74c \u2192 10\ud3b8 \uc11c\ube0c\ucffc\ub9ac\u00b7CTE \u00b7 \uc9c4\ud589: <strong>9\/24<\/strong>\n<\/div>\n\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JOIN 4\uc885 \ube44\uad50 + self\/anti\u00b7\uce74\ud2f0\uc2dc\uc548 \uacf1 \ud568\uc815. 24\ud3b8 \uad50\uc7ac 9\ud3b8.<\/p>\n","protected":false},"author":1,"featured_media":281,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-496","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/496","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/comments?post=496"}],"version-history":[{"count":0,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/496\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media\/281"}],"wp:attachment":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media?parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/categories?post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/tags?post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}