| 1 |
<!DOCTYPE html> |
| 2 |
<html><head> |
| 3 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 4 |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> |
| 5 |
<link href="../sqlite.css" rel="stylesheet"> |
| 6 |
<title>SQLite Syntax: common-table-expression</title> |
| 7 |
<!-- path=../ --> |
| 8 |
</head> |
| 9 |
<body> |
| 10 |
<div class=nosearch> |
| 11 |
<a href="../index.html"> |
| 12 |
<img class="logo" src="../images/sqlite370_banner.gif" alt="SQLite" border="0"> |
| 13 |
</a> |
| 14 |
<div><!-- IE hack to prevent disappearing logo --></div> |
| 15 |
<div class="tagline desktoponly"> |
| 16 |
Small. Fast. Reliable.<br>Choose any three. |
| 17 |
</div> |
| 18 |
<div class="menu mainmenu"> |
| 19 |
<ul> |
| 20 |
<li><a href="../index.html">Home</a> |
| 21 |
<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a> |
| 22 |
<li class='wideonly'><a href='../about.html'>About</a> |
| 23 |
<li class='desktoponly'><a href="../docs.html">Documentation</a> |
| 24 |
<li class='desktoponly'><a href="../download.html">Download</a> |
| 25 |
<li class='wideonly'><a href='../copyright.html'>License</a> |
| 26 |
<li class='desktoponly'><a href="../support.html">Support</a> |
| 27 |
<li class='desktoponly'><a href="../prosupport.html">Purchase</a> |
| 28 |
<li class='search' id='search_menubutton'> |
| 29 |
<a href="javascript:void(0)" onclick='toggle_search()'>Search</a> |
| 30 |
</ul> |
| 31 |
</div> |
| 32 |
<div class="menu submenu" id="submenu"> |
| 33 |
<ul> |
| 34 |
<li><a href='../about.html'>About</a> |
| 35 |
<li><a href='../docs.html'>Documentation</a> |
| 36 |
<li><a href='../download.html'>Download</a> |
| 37 |
<li><a href='../support.html'>Support</a> |
| 38 |
<li><a href='../prosupport.html'>Purchase</a> |
| 39 |
</ul> |
| 40 |
</div> |
| 41 |
<div class="searchmenu" id="searchmenu"> |
| 42 |
<form method="GET" action="../search"> |
| 43 |
<select name="s" id="searchtype"> |
| 44 |
<option value="d">Search Documentation</option> |
| 45 |
<option value="c">Search Changelog</option> |
| 46 |
</select> |
| 47 |
<input type="text" name="q" id="searchbox" value=""> |
| 48 |
<input type="submit" value="Go"> |
| 49 |
</form> |
| 50 |
</div> |
| 51 |
</div> |
| 52 |
<script> |
| 53 |
function toggle_div(nm) { |
| 54 |
var w = document.getElementById(nm); |
| 55 |
if( w.style.display=="block" ){ |
| 56 |
w.style.display = "none"; |
| 57 |
}else{ |
| 58 |
w.style.display = "block"; |
| 59 |
} |
| 60 |
} |
| 61 |
function toggle_search() { |
| 62 |
var w = document.getElementById("searchmenu"); |
| 63 |
if( w.style.display=="block" ){ |
| 64 |
w.style.display = "none"; |
| 65 |
} else { |
| 66 |
w.style.display = "block"; |
| 67 |
setTimeout(function(){ |
| 68 |
document.getElementById("searchbox").focus() |
| 69 |
}, 30); |
| 70 |
} |
| 71 |
} |
| 72 |
function div_off(nm){document.getElementById(nm).style.display="none";} |
| 73 |
window.onbeforeunload = function(e){div_off("submenu");} |
| 74 |
/* Disable the Search feature if we are not operating from CGI, since */ |
| 75 |
/* Search is accomplished using CGI and will not work without it. */ |
| 76 |
if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){ |
| 77 |
document.getElementById("search_menubutton").style.display = "none"; |
| 78 |
} |
| 79 |
/* Used by the Hide/Show button beside syntax diagrams, to toggle the */ |
| 80 |
function hideorshow(btn,obj){ |
| 81 |
var x = document.getElementById(obj); |
| 82 |
var b = document.getElementById(btn); |
| 83 |
if( x.style.display!='none' ){ |
| 84 |
x.style.display = 'none'; |
| 85 |
b.innerHTML='show'; |
| 86 |
}else{ |
| 87 |
x.style.display = ''; |
| 88 |
b.innerHTML='hide'; |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
var antiRobot = 0; |
| 93 |
function antiRobotGo(){ |
| 94 |
if( antiRobot!=3 ) return; |
| 95 |
antiRobot = 7; |
| 96 |
var j = document.getElementById("mtimelink"); |
| 97 |
if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href"); |
| 98 |
} |
| 99 |
function antiRobotDefense(){ |
| 100 |
document.body.onmousedown=function(){ |
| 101 |
antiRobot |= 2; |
| 102 |
antiRobotGo(); |
| 103 |
document.body.onmousedown=null; |
| 104 |
} |
| 105 |
document.body.onmousemove=function(){ |
| 106 |
antiRobot |= 2; |
| 107 |
antiRobotGo(); |
| 108 |
document.body.onmousemove=null; |
| 109 |
} |
| 110 |
setTimeout(function(){ |
| 111 |
antiRobot |= 1; |
| 112 |
antiRobotGo(); |
| 113 |
}, 100) |
| 114 |
antiRobotGo(); |
| 115 |
} |
| 116 |
antiRobotDefense(); |
| 117 |
</script> |
| 118 |
<h1 align='center'>common-table-expression</h1> |
| 119 |
<div class='imgcontainer'> |
| 120 |
<div style="max-width:638px"><svg xmlns='http://www.w3.org/2000/svg' class="pikchr" viewBox="0 0 638.525 167.4"> |
| 121 |
<circle cx="5" cy="29" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 122 |
<polygon points="32,29 20,33 20,24" style="fill:rgb(0,0,0)"/> |
| 123 |
<path d="M9,29L26,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 124 |
<path d="M47,44L122,44A15 15 0 0 0 137 29A15 15 0 0 0 122 14L47,14A15 15 0 0 0 32 29A15 15 0 0 0 47 44Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 125 |
<text x="85" y="29" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">table-name</text> |
| 126 |
<polygon points="160,29 149,33 149,24" style="fill:rgb(0,0,0)"/> |
| 127 |
<path d="M137,29L155,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 128 |
<polygon points="196,29 185,33 185,24" style="fill:rgb(0,0,0)"/> |
| 129 |
<path d="M160,29L191,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 130 |
<path d="M211,44A15 15 0 0 0 227 29A15 15 0 0 0 211 14A15 15 0 0 0 196 29A15 15 0 0 0 211 44Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 131 |
<text x="211" y="29" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">(</text> |
| 132 |
<polygon points="250,29 238,33 238,24" style="fill:rgb(0,0,0)"/> |
| 133 |
<path d="M227,29L244,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 134 |
<polygon points="286,29 274,33 274,24" style="fill:rgb(0,0,0)"/> |
| 135 |
<path d="M250,29L280,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 136 |
<path d="M301,44L395,44A15 15 0 0 0 410 29A15 15 0 0 0 395 14L301,14A15 15 0 0 0 286 29A15 15 0 0 0 301 44Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 137 |
<text x="348" y="29" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">column-name</text> |
| 138 |
<polygon points="446,29 434,33 434,24" style="fill:rgb(0,0,0)"/> |
| 139 |
<path d="M410,29L440,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 140 |
<path d="M461,44A15 15 0 0 0 476 29A15 15 0 0 0 461 14A15 15 0 0 0 446 29A15 15 0 0 0 461 44Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 141 |
<text x="461" y="29" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">)</text> |
| 142 |
<polygon points="511,29 499,33 499,24" style="fill:rgb(0,0,0)"/> |
| 143 |
<path d="M476,29L505,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 144 |
<path d="M47,165L51,165A15 15 0 0 0 66 150A15 15 0 0 0 51 135L47,135A15 15 0 0 0 32 150A15 15 0 0 0 47 165Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 145 |
<text x="49" y="150" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">AS</text> |
| 146 |
<path d="M127,135L147,135A15 15 0 0 0 162 119A15 15 0 0 0 147 104L127,104A15 15 0 0 0 112 119A15 15 0 0 0 127 135Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 147 |
<text x="137" y="119" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">NOT</text> |
| 148 |
<path d="M219,135L337,135A15 15 0 0 0 352 119A15 15 0 0 0 337 104L219,104A15 15 0 0 0 204 119A15 15 0 0 0 219 135Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 149 |
<text x="278" y="119" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">MATERIALIZED</text> |
| 150 |
<path d="M162,119L204,119" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 151 |
<path d="M410,165A15 15 0 0 0 425 150A15 15 0 0 0 410 135A15 15 0 0 0 395 150A15 15 0 0 0 410 165Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 152 |
<text x="410" y="150" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">(</text> |
| 153 |
<polygon points="448,150 437,154 437,145" style="fill:rgb(0,0,0)"/> |
| 154 |
<path d="M425,150L442,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 155 |
<path d="M448,165L552,165L552,135L448,135Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 156 |
<text x="500" y="150" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">select-stmt</text> |
| 157 |
<polygon points="575,150 564,154 564,145" style="fill:rgb(0,0,0)"/> |
| 158 |
<path d="M552,150L570,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 159 |
<path d="M591,165A15 15 0 0 0 606 150A15 15 0 0 0 591 135A15 15 0 0 0 575 150A15 15 0 0 0 591 165Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 160 |
<text x="591" y="150" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">)</text> |
| 161 |
<polygon points="629,150 617,154 617,145" style="fill:rgb(0,0,0)"/> |
| 162 |
<path d="M606,150L623,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 163 |
<circle cx="632" cy="150" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 164 |
<path d="M348,82A15 15 0 0 0 363 66A15 15 0 0 0 348 51A15 15 0 0 0 333 66A15 15 0 0 0 348 82Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 165 |
<text x="348" y="66" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">,</text> |
| 166 |
<polygon points="363,66 374,62 374,71" style="fill:rgb(0,0,0)"/> |
| 167 |
<path d="M410,29 L 417,29 Q 425,29 425,44 L 425,51 Q 425,66 410,66 L 384,66 L 369,66" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 168 |
<path d="M333,66 L 278,66 Q 263,66 263,51 L 263,44 Q 263,29 270,29 L 278,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 169 |
<polygon points="66,93 78,89 78,97" style="fill:rgb(0,0,0)"/> |
| 170 |
<path d="M511,29 L 516,29 Q 522,29 522,44 L 522,78 Q 522,93 507,93 L 87,93 L 72,93" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 171 |
<polygon points="32,150 20,154 20,145" style="fill:rgb(0,0,0)"/> |
| 172 |
<path d="M66,93 L 30,93 Q 15,93 15,108 L 15,135 Q 15,150 20,150 L 26,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 173 |
<polygon points="85,150 73,154 73,145" style="fill:rgb(0,0,0)"/> |
| 174 |
<path d="M66,150L79,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 175 |
<polygon points="112,119 101,124 101,115" style="fill:rgb(0,0,0)"/> |
| 176 |
<path d="M85,150 L 89,150 Q 92,150 92,135 L 92,134 Q 92,119 99,119 L 106,119" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 177 |
<polygon points="204,119 192,124 192,115" style="fill:rgb(0,0,0)"/> |
| 178 |
<path d="M66,150 L 147,150 Q 162,150 170,150 Q 177,150 177,135 L 177,134 Q 177,119 188,119 L 198,119" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 179 |
<polygon points="395,150 383,154 383,145" style="fill:rgb(0,0,0)"/> |
| 180 |
<path d="M352,119 L 360,119 Q 367,119 367,134 L 367,135 Q 367,150 378,150 L 389,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 181 |
<path d="M66,150L395,150" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 182 |
<polygon points="348,6 336,10 336,2" style="fill:rgb(0,0,0)"/> |
| 183 |
<path d="M160,29 L 168,29 Q 175,29 175,17 Q 175,6 190,6 L 327,6 L 342,6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 184 |
<path d="M348,6 L 473,6 Q 488,6 488,17 Q 488,29 495,29 L 503,29" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" /> |
| 185 |
</svg> |
| 186 |
</div><br> |
| 187 |
|
| 188 |
Used by: <a href='./compound-select-stmt.html'>compound-select-stmt</a> <a href='./delete-stmt.html'>delete-stmt</a> <a href='./delete-stmt-limited.html'>delete-stmt-limited</a> <a href='./factored-select-stmt.html'>factored-select-stmt</a> <a href='./insert-stmt.html'>insert-stmt</a> <a href='./select-stmt.html'>select-stmt</a> <a href='./simple-select-stmt.html'>simple-select-stmt</a> <a href='./update-stmt.html'>update-stmt</a> <a href='./update-stmt-limited.html'>update-stmt-limited</a><br></br> |
| 189 |
References: <a href='./select-stmt.html'>select-stmt</a><br></br> |
| 190 |
See also: <a href='../lang_aggfunc.html'>lang_aggfunc.html</a> <a href='../lang_altertable.html'>lang_altertable.html</a> <a href='../lang_attach.html'>lang_attach.html</a> <a href='../lang_createindex.html'>lang_createindex.html</a> <a href='../lang_createtable.html'>lang_createtable.html</a> <a href='../lang_createtrigger.html'>lang_createtrigger.html</a> <a href='../lang_createview.html'>lang_createview.html</a> <a href='../lang_delete.html'>lang_delete.html</a> <a href='../lang_expr.html'>lang_expr.html</a> <a href='../lang_insert.html'>lang_insert.html</a> <a href='../lang_returning.html'>lang_returning.html</a> <a href='../lang_select.html'>lang_select.html</a> <a href='../lang_update.html'>lang_update.html</a> <a href='../lang_upsert.html'>lang_upsert.html</a> <a href='../lang_with.html'>lang_with.html</a> <a href='../partialindex.html'>partialindex.html</a> |
| 191 |
</div> |
| 192 |
|
| 193 |
|
| 194 |
|