{"id":1172,"date":"2016-06-01T23:08:41","date_gmt":"2016-06-01T16:08:41","guid":{"rendered":"http:\/\/www.sqlitetutorial.net\/?page_id=1172"},"modified":"2022-04-03T15:02:51","modified_gmt":"2022-04-03T08:02:51","slug":"sqlite-subquery","status":"publish","type":"page","link":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/","title":{"rendered":"SQLite Subquery"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you will learn about the SQLite subquery to construct&nbsp;more readable and complex queries.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Introduction to SQLite subquery<\/h2>\r\n\r\n\r\n\r\n<p>A subquery is a <code>SELECT<\/code> statement nested in another statement. See the following statement.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> column_1\r\n<span class=\"hljs-keyword\">FROM<\/span> table_1\r\n<span class=\"hljs-keyword\">WHERE<\/span> column_1 = (\r\n   <span class=\"hljs-keyword\">SELECT<\/span> column_1 \r\n   <span class=\"hljs-keyword\">FROM<\/span> table_2\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The following query is the <strong>outer query<\/strong>:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> column_1\r\n  <span class=\"hljs-keyword\">FROM<\/span> table_1\r\n <span class=\"hljs-keyword\">WHERE<\/span> colum_1 =<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>And the following query is the <strong>subquery<\/strong>.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">(<span class=\"hljs-keyword\">SELECT<\/span> column_1\r\n  <span class=\"hljs-keyword\">FROM<\/span> table_2)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>You must use a pair of parentheses to enclose a subquery. Note that you can nest a subquery inside another subquery with a certain depth.<\/p>\r\n\r\n\r\n\r\n<p>Typically, a subquery returns a single row as an atomic value, though it may return multiple rows for comparing values with the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-in\/\">IN<\/a><\/code> operator.<\/p>\r\n\r\n\r\n\r\n<p>You can use a subquery in the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-select\/\">SELECT<\/a><\/code>, <code>FROM<\/code>, <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-where\/\">WHERE<\/a><\/code>,&nbsp;and <code>JOIN<\/code> clauses.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">SQLite subquery examples<\/h2>\r\n\r\n\r\n\r\n<p>We will use the <code>tracks<\/code> and <code>albums<\/code> tables from the <a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-sample-database\/\">sample database<\/a> for the demonstration.<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"224\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\" alt=\"\" class=\"wp-image-1582\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png 404w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums-300x166.png 300w\" sizes=\"auto, (max-width: 404px) 100vw, 404px\" \/><\/figure>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">1) SQLite subquery in the WHERE clause example<\/h3>\r\n\r\n\r\n\r\n<p>You can use a simple subquery as a search condition. For example, the following statement returns all the tracks in the album with the title &nbsp;<code>Let There Be Rock<\/code><\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> trackid,\r\n       <span class=\"hljs-keyword\">name<\/span>,\r\n       albumid\r\n<span class=\"hljs-keyword\">FROM<\/span> tracks\r\n<span class=\"hljs-keyword\">WHERE<\/span> albumid = (\r\n   <span class=\"hljs-keyword\">SELECT<\/span> albumid\r\n   <span class=\"hljs-keyword\">FROM<\/span> albums\r\n   <span class=\"hljs-keyword\">WHERE<\/span> title = <span class=\"hljs-string\">'Let There Be Rock'<\/span>\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"272\" height=\"181\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Subquery-example.png\" alt=\"SQLite Subquery example\" class=\"wp-image-1173\"\/><\/figure>\r\n\r\n\r\n\r\n<p>The subquery returns the id of the album with the title <code>'Let There Be Rock'<\/code>. The query uses the equal operator (=) to compare <code>albumid<\/code> returned by the subquery with the &nbsp;<code>albumid<\/code> in the <code>tracks<\/code> table.<\/p>\r\n\r\n\r\n\r\n<p>If the subquery returns multiple values, you can use the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-in\/\">IN<\/a><\/code> operator to check for the existence of a single value against a set of value.<\/p>\r\n\r\n\r\n\r\n<p>See the following <code>employees<\/code> and <code>customers<\/code> table in the sample database:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"428\" height=\"344\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/customers_employees.png\" alt=\"\" class=\"wp-image-1578\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/customers_employees.png 428w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/customers_employees-300x241.png 300w\" sizes=\"auto, (max-width: 428px) 100vw, 428px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>For example, the following query returns the customers whose sales representatives are in Canada.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> customerid,\r\n       firstname,\r\n       lastname\r\n  <span class=\"hljs-keyword\">FROM<\/span> customers\r\n <span class=\"hljs-keyword\">WHERE<\/span> supportrepid <span class=\"hljs-keyword\">IN<\/span> (\r\n           <span class=\"hljs-keyword\">SELECT<\/span> employeeid\r\n             <span class=\"hljs-keyword\">FROM<\/span> employees\r\n            <span class=\"hljs-keyword\">WHERE<\/span> country = <span class=\"hljs-string\">'Canada'<\/span>\r\n       );\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"229\" height=\"239\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Subquery-with-IN-operator-example.png\" alt=\"SQLite Subquery with IN operator example\" class=\"wp-image-1174\"\/><\/figure>\r\n\r\n\r\n\r\n<p>The subquery returns a list of ids of the employees who locate in Canada. The outer query uses the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-in\/\">IN<\/a><\/code> operator to find the customers who have the sales representative id in the list.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">2) SQLite subquery in the FROM clause example<\/h3>\r\n\r\n\r\n\r\n<p>Sometimes you want to apply <a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-aggregate-functions\/\">aggregate functions<\/a> to a column multiple times. For example, first, you want to sum the size of an album and then calculate the average size of all albums.&nbsp;<span style=\"line-height: 1.5;\">You may come up with the following query.<\/span><\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">AVG<\/span>(<span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">bytes<\/span>) \r\n<span class=\"hljs-keyword\">FROM<\/span> tracks\r\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> albumid;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>This query is not valid.<\/p>\r\n\r\n\r\n\r\n<p>To fix it, you can use a subquery in the <code>FROM<\/code> clause as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n\t<span class=\"hljs-keyword\">AVG<\/span>(album.size)\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n\t(\r\n\t\t<span class=\"hljs-keyword\">SELECT<\/span>\r\n\t\t\t<span class=\"hljs-keyword\">SUM<\/span>(<span class=\"hljs-keyword\">bytes<\/span>) <span class=\"hljs-keyword\">SIZE<\/span>\r\n\t\t<span class=\"hljs-keyword\">FROM<\/span>\r\n\t\t\ttracks\r\n\t\t<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span>\r\n\t\t\talbumid\r\n\t) <span class=\"hljs-keyword\">AS<\/span> album;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<pre class=\"wp-block-preformatted lang:batch highlight:0 decode:true\">AVG(album.size)\r\n---------------\r\n  338288920.317<\/code><\/pre>\r\n\r\n\r\n\r\n<p>In this case, SQLite first executes the subquery in the <code>FROM<\/code> clause and returns a result set. Then, SQLite uses this result set as a derived table in the outer query.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">SQLite correlated subquery<\/h2>\r\n\r\n\r\n\r\n<p>All the subqueries you have seen so far can be executed independently. In other words, it does not depend&nbsp;on the outer query.<\/p>\r\n\r\n\r\n\r\n<p>The correlated subquery is a subquery that uses the values from the outer query. Unlike an ordinal subquery, a correlated subquery cannot be executed independently.<\/p>\r\n\r\n\r\n\r\n<p>The correlated subquery is not efficient because it is evaluated for each row processed by the outer query.<\/p>\r\n\r\n\r\n\r\n<p>The following query uses a correlated subquery to return the albums whose size is less than 10MB.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> albumid,\r\n       title\r\n  <span class=\"hljs-keyword\">FROM<\/span> albums\r\n <span class=\"hljs-keyword\">WHERE<\/span> <span class=\"hljs-number\">10000000<\/span> &gt; (\r\n                      <span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">sum<\/span>(<span class=\"hljs-keyword\">bytes<\/span>) \r\n                        <span class=\"hljs-keyword\">FROM<\/span> tracks\r\n                       <span class=\"hljs-keyword\">WHERE<\/span> tracks.AlbumId = albums.AlbumId\r\n                  )\r\n <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> title;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"241\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Correlated-Subquery-Example.png\" alt=\"SQLite Correlated Subquery Example\" class=\"wp-image-1175\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Correlated-Subquery-Example.png 595w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Correlated-Subquery-Example-300x122.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>How the query works.<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\"><li>For each row processed in the outer query, the correlated subquery calculates the size of the albums from the tracks that belong the current album using the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-sum\/\">SUM<\/a><\/code> function.<\/li><li>The predicate in the <code><a href=\"https:\/\/www.sqlitetutorial.net\/sqlite-where\/\">WHERE<\/a><\/code> clause filters the albums that have the size greater than or equal 10MB (10000000 bytes).<\/li><\/ul>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">SQLite correlated subquery in the SELECT clause example<\/h3>\r\n\r\n\r\n\r\n<p>The following query uses a correlated subquery in the <code>SELECT<\/code> clause to return the number of tracks in an album.<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> albumid,\r\n       title,\r\n       (\r\n           <span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">count<\/span>(trackid) \r\n             <span class=\"hljs-keyword\">FROM<\/span> tracks\r\n            <span class=\"hljs-keyword\">WHERE<\/span> tracks.AlbumId = albums.AlbumId\r\n       )\r\n       tracks_count\r\n  <span class=\"hljs-keyword\">FROM<\/span> albums\r\n <span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> tracks_count <span class=\"hljs-keyword\">DESC<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"243\" src=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Subquery-in-SELECT-clause-example.png\" alt=\"SQLite Subquery in SELECT clause example\" class=\"wp-image-1176\" srcset=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Subquery-in-SELECT-clause-example.png 699w, https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2016\/06\/SQLite-Subquery-in-SELECT-clause-example-300x104.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>In this tutorial, we have introduced you to the subquery and shown&nbsp;various ways to use a subquery in a query to select data from tables.<\/p>\r\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1172\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\"\n\t\t\t\tdata-post-title=\"SQLite Subquery\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1172\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\"\n\t\t\t\tdata-post-title=\"SQLite Subquery\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you will learn about the SQLite subquery to construct&nbsp;more readable and complex queries. Introduction to SQLite subquery A subquery is a SELECT statement nested in another statement. See the following statement. The following query is the outer query: And the following query is the subquery. You must use a pair of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":24,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1172","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQLite Subquery: An Ultimate Guide for SQLite The Novices<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQLite Subquery: An Ultimate Guide for SQLite The Novices\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\" \/>\n<meta property=\"og:site_name\" content=\"SQLite Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-03T08:02:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\"},\"headline\":\"SQLite Subquery\",\"datePublished\":\"2016-06-01T16:08:41+00:00\",\"dateModified\":\"2022-04-03T08:02:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\"},\"wordCount\":554,\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\",\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\",\"url\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\",\"name\":\"SQLite Subquery: An Ultimate Guide for SQLite The Novices\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\",\"datePublished\":\"2016-06-01T16:08:41+00:00\",\"dateModified\":\"2022-04-03T08:02:51+00:00\",\"description\":\"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage\",\"url\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\",\"contentUrl\":\"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png\",\"width\":404,\"height\":224,\"caption\":\"SQLite json_group_array() function - sample tables\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlitetutorial.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLite Subquery\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#website\",\"url\":\"https:\/\/www.sqlitetutorial.net\/\",\"name\":\"SQLite Tutorial\",\"description\":\"A Step-by-step SQLite Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427\",\"name\":\"admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQLite Subquery: An Ultimate Guide for SQLite The Novices","description":"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/","og_locale":"en_US","og_type":"article","og_title":"SQLite Subquery: An Ultimate Guide for SQLite The Novices","og_description":"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.","og_url":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/","og_site_name":"SQLite Tutorial","article_modified_time":"2022-04-03T08:02:51+00:00","og_image":[{"url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#article","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/"},"author":{"name":"admin","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427"},"headline":"SQLite Subquery","datePublished":"2016-06-01T16:08:41+00:00","dateModified":"2022-04-03T08:02:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/"},"wordCount":554,"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png","inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/","url":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/","name":"SQLite Subquery: An Ultimate Guide for SQLite The Novices","isPartOf":{"@id":"https:\/\/www.sqlitetutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png","datePublished":"2016-06-01T16:08:41+00:00","dateModified":"2022-04-03T08:02:51+00:00","description":"This tutorial introduces you to the SQLite subquery and shows you many examples of using the subqueries select data from multiple tables.","breadcrumb":{"@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#primaryimage","url":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png","contentUrl":"https:\/\/www.sqlitetutorial.net\/wp-content\/uploads\/2018\/11\/tracks_albums.png","width":404,"height":224,"caption":"SQLite json_group_array() function - sample tables"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlitetutorial.net\/sqlite-subquery\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlitetutorial.net\/"},{"@type":"ListItem","position":2,"name":"SQLite Subquery"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlitetutorial.net\/#website","url":"https:\/\/www.sqlitetutorial.net\/","name":"SQLite Tutorial","description":"A Step-by-step SQLite Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlitetutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlitetutorial.net\/#\/schema\/person\/6d69b968cad0102e30d6694ed8dc6427","name":"admin"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/comments?post=1172"}],"version-history":[{"count":1,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1172\/revisions"}],"predecessor-version":[{"id":2785,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/1172\/revisions\/2785"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"https:\/\/www.sqlitetutorial.net\/wp-json\/wp\/v2\/media?parent=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}