{"id":489,"date":"2026-05-17T07:02:13","date_gmt":"2026-05-16T23:02:13","guid":{"rendered":"https:\/\/junai.ai\/blog\/pg-where-clause-6\/"},"modified":"2026-05-17T07:02:13","modified_gmt":"2026-05-16T23:02:13","slug":"pg-where-clause-6","status":"publish","type":"post","link":"https:\/\/junai.ai\/blog\/pg-where-clause-6\/","title":{"rendered":"WHERE \uc808 BETWEEN\u00b7IN\u00b7LIKE\u00b7NULL (\uae30\ucd08 6\ud3b8)"},"content":{"rendered":"\n<!-- WordPress REST API \ubc1c\ud589\uc6a9 HTML (\uc790\ub3d9 \uc0dd\uc131) -->\n<!-- WP-FEATURED-MEDIA-ID: 271 -->\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 6\ud3b8 \/ 24\ud3b8<\/span>\n  <h1>WHERE \uc808 \u2014 BETWEEN\u00b7IN\u00b7LIKE\u00b7NULL<\/h1>\n  <p class=\"sub\">\uc870\uac74 \ud45c\ud604 5\uc885\uacfc NULL 3\uac12 \ub17c\ub9ac\uc758 \ud568\uc815. SQL \uae30\ucd08 \ud30c\ud2b8 \uccab \ud3b8.<\/p>\n  <div class=\"meta\"><span>SQL \uae30\ucd08<\/span><span>\uc77d\ub294 \uc2dc\uac04 7\ubd84<\/span><span>2026-05-17<\/span><\/div>\n  <img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/hero-51.jpg\" alt=\"WHERE \uc808\uc758 \ub2e4\uc591\ud55c \ube44\uad50 \uc5f0\uc0b0\uc790\ub4e4\uc774 \ub3c4\uc2dd\uc73c\ub85c \ub098\uc5f4\ub41c \uc77c\ub7ec\uc2a4\ud2b8\">\n<\/header>\n\n<div class=\"container\">\n<article>\n\n<p>WHERE \ub294 SQL \ucffc\ub9ac\uc758 \uc808\ubc18 \u2014 &#8220;\uc5b4\ub5a4 \ud589\uc744 \uac00\uc838\uc62c\uae4c&#8221; \ub97c \uacb0\uc815\ud569\ub2c8\ub2e4. \ub2e8\uc21c \ube44\uad50(<code>=<\/code>\u00b7<code>><\/code>)\ubd80\ud130 BETWEEN, IN, LIKE, NULL \uae4c\uc9c0 \uc815\ud655\ud788 \uc54c\uc544\ub450\uba74 \ucffc\ub9ac\uc758 8\ud560\uc774 \uac00\ubcbc\uc6cc\uc9d1\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \ubaa8\ub4e0 \uc785\ubb38\uc790\uac00 \ud55c \ubc88\uc529 \ub2f9\ud558\ub294 <strong>NULL 3\uac12 \ub17c\ub9ac<\/strong>\uc758 \ud568\uc815\ub3c4 \uc815\ub9ac\ud569\ub2c8\ub2e4.<\/p>\n\n<h2>\ube44\uad50 \uc5f0\uc0b0\uc790 \u2014 6\uac1c<\/h2>\n\n<div class=\"tablewrap\">\n<table>\n  <thead>\n    <tr><th>\uc5f0\uc0b0\uc790<\/th><th>\uc758\ubbf8<\/th><th>\uc608\uc2dc<\/th><\/tr>\n  <\/thead>\n  <tbody>\n    <tr><td data-label=\"\uc5f0\uc0b0\uc790\">=<\/td><td data-label=\"\uc758\ubbf8\">\uac19\uc74c<\/td><td data-label=\"\uc608\uc2dc\"><code>WHERE id = 5<\/code><\/td><\/tr>\n    <tr><td data-label=\"\uc5f0\uc0b0\uc790\">&lt;&gt; \ub610\ub294 !=<\/td><td data-label=\"\uc758\ubbf8\">\ub2e4\ub984<\/td><td data-label=\"\uc608\uc2dc\"><code>WHERE status &lt;&gt; 'paid'<\/code><\/td><\/tr>\n    <tr><td data-label=\"\uc5f0\uc0b0\uc790\">&lt; &gt;<\/td><td data-label=\"\uc758\ubbf8\">\ud06c\ub2e4\/\uc791\ub2e4<\/td><td data-label=\"\uc608\uc2dc\"><code>WHERE age &gt; 18<\/code><\/td><\/tr>\n    <tr><td data-label=\"\uc5f0\uc0b0\uc790\">&lt;= &gt;=<\/td><td data-label=\"\uc758\ubbf8\">\uc774\uc0c1\/\uc774\ud558<\/td><td data-label=\"\uc608\uc2dc\"><code>WHERE price &lt;= 10000<\/code><\/td><\/tr>\n  <\/tbody>\n<\/table>\n<\/div>\n\n<pre><code>SELECT * FROM users WHERE age &gt;= 19 AND age &lt; 65;\nSELECT * FROM users WHERE name &lt;&gt; '\uad00\ub9ac\uc790';<\/code><\/pre>\n\n<h2>AND \u00b7 OR \u00b7 NOT \u2014 \uc870\ud569<\/h2>\n\n<pre><code>SELECT * FROM orders\nWHERE  status = 'paid'\n   AND total &gt;= 50000\n   AND (region = 'KR' OR region = 'JP')\n   AND NOT cancelled;<\/code><\/pre>\n\n<p>\uc6b0\uc120\uc21c\uc704: <strong>NOT &gt; AND &gt; OR<\/strong>. \ud5f7\uac08\ub9ac\uba74 \uad04\ud638. <code>WHERE a AND b OR c<\/code> \ub294 <code>WHERE (a AND b) OR c<\/code> \uc640 \uac19\uc2b5\ub2c8\ub2e4. \uc758\ub3c4\uac00 (a AND (b OR c)) \uba74 \ubc18\ub4dc\uc2dc \uad04\ud638.<\/p>\n\n<h2>BETWEEN \u2014 \ubc94\uc704 (\uc591 \ub05d \ud3ec\ud568)<\/h2>\n\n<pre><code>-- \ub3d9\uc77c\nWHERE age BETWEEN 19 AND 64\nWHERE age &gt;= 19 AND age &lt;= 64\n\n-- \ubd80\uc815\nWHERE age NOT BETWEEN 19 AND 64\n\n-- \ub0a0\uc9dc\uc5d0\ub3c4\nWHERE created_at BETWEEN '2026-01-01' AND '2026-12-31'<\/code><\/pre>\n\n<div class=\"warnbox\">\n  <p><strong>\ub0a0\uc9dc BETWEEN \uc758 \ud568\uc815.<\/strong> <code>'2026-12-31'<\/code> \uc740 \uc2dc\uac04\uc774 <code>00:00:00<\/code> \uc785\ub2c8\ub2e4. <strong>12\uc6d4 31\uc77c \uc624\ud6c4 \ub370\uc774\ud130\uac00 \ub204\ub77d<\/strong>\ub429\ub2c8\ub2e4. \uc2dc\uacc4\uc5f4\uc740 <code>created_at &gt;= '2026-01-01' AND created_at &lt; '2027-01-01'<\/code> \uac19\uc740 \ubc18-\uac1c\uad6c\uac04\uc774 \uc548\uc804\ud569\ub2c8\ub2e4.<\/p>\n<\/div>\n\n<h2>IN \u2014 &#8220;\uc774 \uc911 \ud558\ub098&#8221;<\/h2>\n\n<pre><code>WHERE status IN ('pending', 'paid', 'shipped')\nWHERE region NOT IN ('CN', 'RU')\n\n-- \uc11c\ube0c\ucffc\ub9ac\ub3c4 \uac00\ub2a5 (10\ud3b8\uc5d0\uc11c \uc790\uc138\ud788)\nWHERE user_id IN (SELECT id FROM users WHERE active = true)<\/code><\/pre>\n\n<p>OR \uc758 \uc0ac\ucd0c\uc774\uc9c0\ub9cc \uac00\ub3c5\uc131\uc774 \ud6e8\uc52c \uc88b\uc544\uc694. 5\uac1c \uc774\uc0c1\uc774\uba74 IN, 2-3\uac1c\ub294 OR \uac00 \uc790\uc5f0\uc2a4\ub7fd\uc2b5\ub2c8\ub2e4.<\/p>\n\n<h2>LIKE \u00b7 ILIKE \u2014 \ud328\ud134 \ub9e4\uce6d<\/h2>\n\n<pre><code>-- % : 0\uac1c \uc774\uc0c1\uc758 \uc784\uc758 \ubb38\uc790\n-- _ : \uc815\ud655\ud788 1\uac1c \ubb38\uc790\n\nWHERE name LIKE '\uc900%'         -- \"\uc900\" \uc73c\ub85c \uc2dc\uc791\nWHERE name LIKE '%\uc131'         -- \"\uc131\" \uc73c\ub85c \ub05d\nWHERE name LIKE '%\ubc15%'        -- \"\ubc15\" \ud3ec\ud568\n\n-- ILIKE : \ub300\uc18c\ubb38\uc790 \ubb34\uc2dc (PostgreSQL \ud655\uc7a5)\nWHERE email ILIKE '%@gmail.com'\n\n-- \uc640\uc77c\ub4dc\uce74\ub4dc \uc790\uccb4\ub97c \ucc3e\uace0 \uc2f6\uc744 \ub54c ESCAPE\nWHERE title LIKE '%50\\%%' ESCAPE '\\'   -- \uc2e4\uc81c % \uae30\ud638 \ub9e4\uce58<\/code><\/pre>\n\n<div class=\"databox\">\n  <p><strong>LIKE \uc640 \uc778\ub371\uc2a4.<\/strong> <code>'\uc900%'<\/code> (\uc55e\ubd80\ubd84 \uace0\uc815) \uc740 \uc77c\ubc18 B-Tree \uc778\ub371\uc2a4\uac00 \uc798 \ub4e3\uc9c0\ub9cc, <code>'%\uc131'<\/code> \uc774\ub098 <code>'%\ubc15%'<\/code> \ub294 \uc778\ub371\uc2a4\ub97c \ubabb \uc501\ub2c8\ub2e4. \uac80\uc0c9\uc774 \ub9ce\uc73c\uba74 <strong>trigram \uc778\ub371\uc2a4(pg_trgm)<\/strong> \ub610\ub294 <strong>full-text search<\/strong> \ub97c 16\ud3b8\uc5d0\uc11c \ub2e4\ub8f9\ub2c8\ub2e4.<\/p>\n<\/div>\n\n<h2>IS NULL \u2014 NULL \ube44\uad50\uc758 \ub2e8 \ud558\ub098\uc758 \uc815\ub2f5<\/h2>\n\n<pre><code>-- \u274c \uc548 \ub428 \u2014 NULL \uc740 \uc5b4\ub5a4 \ube44\uad50\uc5d0\ub3c4 NULL \uc744 \ubc18\ud658 (\ucc38\ub3c4 \uac70\uc9d3\ub3c4 \uc544\ub2d8)\nWHERE phone = NULL          -- \ud56d\uc0c1 \ube48 \uacb0\uacfc\nWHERE phone &lt;&gt; NULL          -- \ud56d\uc0c1 \ube48 \uacb0\uacfc\n\n-- \u2705 \uc815\ub2f5\nWHERE phone IS NULL\nWHERE phone IS NOT NULL<\/code><\/pre>\n\n<p>\uc774\uac8c SQL \uc758 <strong>3\uac12 \ub17c\ub9ac(three-valued logic)<\/strong> \uc785\ub2c8\ub2e4 \u2014 \uacb0\uacfc\uac00 true\/false\/UNKNOWN(NULL) \uc138 \uac00\uc9c0. WHERE \ub294 true \uc778 \ud589\ub9cc \ubc18\ud658\ud558\ubbc0\ub85c UNKNOWN \uc740 false \ucc98\ub7fc \ucc98\ub9ac\ub429\ub2c8\ub2e4 \u2014 \uadf8\ub798\uc11c <code>phone = NULL<\/code> \uc740 \ud56d\uc0c1 \ube48 \uacb0\uacfc.<\/p>\n\n<div class=\"warnbox\">\n  <p><strong>NULL \uc758 \ub2e4\ub978 \ud568\uc815\ub4e4.<\/strong><\/p>\n  <p>\u00b7 <code>NULL + 1<\/code> = NULL. \ubaa8\ub4e0 \uc0b0\uc220\uc774 NULL \uc744 \ub9cc\ub098\uba74 NULL.<\/p>\n  <p>\u00b7 <code>NULL OR true<\/code> = true (\ub2e4\ud589). <code>NULL AND true<\/code> = NULL.<\/p>\n  <p>\u00b7 <code>NOT IN (subquery)<\/code> \uc5d0\uc11c subquery \uacb0\uacfc\uc5d0 NULL \ud558\ub098\ub9cc \uc788\uc73c\uba74 <strong>\uc804\uccb4\uac00 \ube48 \uacb0\uacfc<\/strong>. <code>NOT EXISTS<\/code> \uad8c\uc7a5.<\/p>\n  <p>\u00b7 COUNT(col) \uc740 NULL \uc744 \uc138\uc9c0 \uc54a\uace0, COUNT(*) \ub9cc \ubaa8\ub4e0 \ud589\uc744 \uc149\ub2c8\ub2e4.<\/p>\n<\/div>\n\n<h2>\uc2e4\uc804 \ud328\ud134 \u2014 COALESCE \uc640 NULLIF<\/h2>\n\n<pre><code>-- COALESCE : \uccab NULL \uc544\ub2cc \uac12\nSELECT name, COALESCE(phone, email, '\uc5f0\ub77d\ucc98 \uc5c6\uc74c') AS contact\nFROM users;\n\n-- NULLIF : \ub450 \uac12\uc774 \uac19\uc73c\uba74 NULL \ubc18\ud658 (DIVISION BY ZERO \ubc29\uc5b4)\nSELECT total \/ NULLIF(count, 0) AS avg FROM stats;\n-- count \uac00 0 \uc774\uba74 NULL \ubc18\ud658 (\uc5d0\ub7ec \uc548 \ub0a8)<\/code><\/pre>\n\n<h2>\ud55c \uc904 \uc694\uc57d \u2014 WHERE \uc758 \uccb4\ud06c\ub9ac\uc2a4\ud2b8<\/h2>\n\n<ul>\n  <li>\uac19\uc740 \uac12 \ube44\uad50 \u2192 <code>=<\/code> \u00b7 <code>IN<\/code><\/li>\n  <li>\ubc94\uc704 \u2192 <code>&gt;=<\/code> \u00b7 <code>&lt;<\/code> (\ub0a0\uc9dc\ub294 \ubc18-\uac1c\uad6c\uac04, BETWEEN \ud568\uc815)<\/li>\n  <li>\ud328\ud134 \u2192 <code>LIKE<\/code> \/ <code>ILIKE<\/code> (\uc55e \uc640\uc77c\ub4dc\uce74\ub4dc = \uc778\ub371\uc2a4 \ubabb \uc500)<\/li>\n  <li>NULL \u2192 <strong>\ud56d\uc0c1<\/strong> <code>IS NULL<\/code> \/ <code>IS NOT NULL<\/code><\/li>\n  <li>NULL \uc0b0\uc220 \u2192 <code>COALESCE<\/code> \ub85c \uae30\ubcf8\uac12<\/li>\n  <li>0 \ub098\ub217\uc148 \u2192 <code>NULLIF(x, 0)<\/code><\/li>\n<\/ul>\n\n<div class=\"cta\">\n  <h3>7\ud3b8 \u2014 ORDER BY\u00b7LIMIT\u00b7OFFSET<\/h3>\n  <p>\uc815\ub82c\uacfc \ud398\uc774\uc9c0\ub124\uc774\uc158, \uadf8\ub9ac\uace0 OFFSET \ub9cc \uc4f0\uba74 \uc65c \ub290\ub824\uc9c0\ub294\uc9c0(keyset pagination).<\/p>\n<\/div>\n\n<div class=\"series-nav\">\n  <strong>\ud83d\udcda PostgreSQL \ubc30\uc6b0\uae30 \uad50\uc7ac<\/strong><br>\n  \uc774\uc804: 5\ud3b8 CRUD \u00b7 \ud604\uc7ac: <strong>6\ud3b8 (SQL \uae30\ucd08)<\/strong> \u00b7 \ub2e4\uc74c \u2192 7\ud3b8 ORDER BY \u00b7 \uc9c4\ud589: <strong>6\/24<\/strong>\n<\/div>\n\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>WHERE \ud45c\ud604 5\uc885 + NULL 3\uac12 \ub17c\ub9ac \ud568\uc815. 24\ud3b8 \uad50\uc7ac 6\ud3b8.<\/p>\n","protected":false},"author":1,"featured_media":271,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-489","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\/489","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=489"}],"version-history":[{"count":0,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/489\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media\/271"}],"wp:attachment":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media?parent=489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/categories?post=489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/tags?post=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}