{"id":2153,"date":"2013-05-08T01:31:26","date_gmt":"2013-05-08T09:31:26","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=2153"},"modified":"2023-10-23T06:50:21","modified_gmt":"2023-10-23T13:50:21","slug":"mysql-temporary-table","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-temporary-table\/","title":{"rendered":"MySQL Temporary Tables"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, we will discuss <strong>MySQL temporary tables<\/strong> and show you how to create, use, and drop temporary tables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to MySQL temporary tables<\/h2>\n\n\n\n<p>In MySQL, a temporary table is a special type of table that allows you to store a temporary result set, which you can reuse several times in a single session.<\/p>\n\n\n\n<p>A temporary table is handy when it is impossible or expensive to query data that requires a single <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\"><code>SELECT<\/code><\/a> statement. In such cases, you can use a temporary table to store the immediate result and use another query to process it.<\/p>\n\n\n\n<p>A MySQL temporary table has the following features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A temporary table is created by using <code>CREATE TEMPORARY TABLE<\/code> statement. Notice that the keyword <code>TEMPORARY<\/code> is added between the&nbsp;<code>CREATE<\/code> and <code>TABLE<\/code> keywords.<\/li>\n\n\n\n<li>MySQL removes the temporary table automatically when the session ends or the connection is terminated. Also, you can use the &nbsp;<a href=\"https:\/\/www.mysqltutorial.org\/mysql-drop-table\"><code>DROP TABLE<\/code><\/a> statement to remove a temporary table explicitly when you are no longer using it.<\/li>\n\n\n\n<li>A temporary table is only available and accessible to the client that creates it. Different clients can create temporary tables with the same name without causing errors because only the client that creates the temporary table can see it. However, in the same session, two temporary tables cannot share the same name.<\/li>\n\n\n\n<li>A temporary table can have the same name as a regular table in a database. For example, if you create a temporary table named <code>employees<\/code> in the <a title=\"MySQL Sample Database\" href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/mysql-sample-database\/\">sample database<\/a>, the existing <code>employees<\/code> table becomes inaccessible. Every query you issue against the <code>employees<\/code> table is now referring to the temporary table&nbsp;<code>employees<\/code>. When you drop&nbsp;the <code>employees<\/code> temporary table, the regular <code>employees<\/code> table is available and accessible.<\/li>\n<\/ul>\n\n\n\n<p>Even though a temporary table can have the same name as a regular table, it is not recommended. Because this may lead to confusion and potentially cause an unexpected data loss.<\/p>\n\n\n\n<p>For example, if the connection to the database server is lost and you reconnect to the server automatically, you cannot differentiate between the temporary table and the regular one. <\/p>\n\n\n\n<p>Then, you may issue a <code>DROP TABLE<\/code> &nbsp;statement to remove the permanent table instead of the temporary table, which is not expected. <\/p>\n\n\n\n<p>To avoid this issue, you can use the <code>DROP TEMPORARY TABLE<\/code> statement to drop a temporary table instead  of the <code>DROP TABLE<\/code> statement<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">MySQL CREATE TEMPORARY TABLE statement<\/h2>\n\n\n\n<p>The syntax of the <code>CREATE TEMPORARY TABLE<\/code> statement is similar to the syntax of the <code>CREATE TABLE<\/code> statement except for the <code>TEMPORARY<\/code> keyword:<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name(\n   column1 datatype <span class=\"hljs-keyword\">constraints<\/span>,\n   column1 datatype <span class=\"hljs-keyword\">constraints<\/span>,\n   ...,\n   table_constraints\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>\n\n\n<p>To create a temporary table whose structure is based on an existing table, you cannot use the <code>CREATE TEMPORARY TABLE ... LIKE<\/code> statement. Instead, you use the following syntax:<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> temp_table_name\n<span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> original_table\n<span class=\"hljs-keyword\">LIMIT<\/span> <span class=\"hljs-number\">0<\/span>;<\/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>\n\n\n<h3 class=\"wp-block-heading\">1) Creating a temporary table example<\/h3>\n\n\n\n<p>First, create a new temporary table called <code>credits<\/code> that stores customers&#8217; credits:<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> credits(\n  customerNumber <span class=\"hljs-built_in\">INT<\/span> PRIMARY <span class=\"hljs-keyword\">KEY<\/span>, \n  creditLimit <span class=\"hljs-built_in\">DEC<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>)\n);<\/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>\n\n\n<p>Then, insert rows from the <code>customers<\/code> table into the temporary table <code>credits<\/code>:<\/p>\n\n\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\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> credits(customerNumber, creditLimit)\n<span class=\"hljs-keyword\">SELECT<\/span> \n  customerNumber, \n  creditLimit \n<span class=\"hljs-keyword\">FROM<\/span> \n  customers \n<span class=\"hljs-keyword\">WHERE<\/span> \n  creditLimit &gt; <span class=\"hljs-number\">0<\/span>;<\/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>\n\n\n<h3 class=\"wp-block-heading\">2) Creating a temporary table whose structure is based on a query example<\/h3>\n\n\n\n<p>The following example creates a temporary table that stores the top 10 customers by revenue. The structure of the temporary table is derived from a <code>SELECT<\/code> statement:<\/p>\n\n\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\">CREATE<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> top_customers\n<span class=\"hljs-keyword\">SELECT<\/span> p.customerNumber, \n       c.customerName, \n       <span class=\"hljs-keyword\">ROUND<\/span>(<span class=\"hljs-keyword\">SUM<\/span>(p.amount),<span class=\"hljs-number\">2<\/span>) sales\n<span class=\"hljs-keyword\">FROM<\/span> payments p\n<span class=\"hljs-keyword\">INNER<\/span> <span class=\"hljs-keyword\">JOIN<\/span> customers c <span class=\"hljs-keyword\">ON<\/span> c.customerNumber = p.customerNumber\n<span class=\"hljs-keyword\">GROUP<\/span> <span class=\"hljs-keyword\">BY<\/span> p.customerNumber\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> sales <span class=\"hljs-keyword\">DESC<\/span>\n<span class=\"hljs-keyword\">LIMIT<\/span> <span class=\"hljs-number\">10<\/span>;<\/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>\n\n\n<p>Now, you can query data from the <code>top_customers<\/code> temporary table like querying from a permanent table:<\/p>\n\n\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> \n    customerNumber, \n    customerName, \n    sales\n<span class=\"hljs-keyword\">FROM<\/span>\n    top_customers\n<span class=\"hljs-keyword\">ORDER<\/span> <span class=\"hljs-keyword\">BY<\/span> sales;<\/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>\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"346\" height=\"219\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png\" alt=\"MySQL Temporary Table Example\" class=\"wp-image-6740\" title=\"MySQL Temporary Table Example\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png 346w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example-200x127.png 200w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Dropping a temporary table<\/h2>\n\n\n\n<p>You can use the <code>DROP TABLE<\/code> statement to remove temporary tables however it is good practice to add the <code>TEMPORARY<\/code> keyword as follows:<\/p>\n\n\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\">DROP<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> table_name;<\/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>\n\n\n<p>The <code>DROP TEMPORARY TABLE<\/code>&nbsp; statement removes a temporary table only, not a regular table. It helps you avoid the risk of mistakenly dropping a regular table with the same name as the temporary table.<\/p>\n\n\n\n<p>For example, to remove the <code>top_customers<\/code> temporary table, you use the following statement:<\/p>\n\n\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\">DROP<\/span> <span class=\"hljs-keyword\">TEMPORARY<\/span> <span class=\"hljs-keyword\">TABLE<\/span> top_customers;<\/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>\n\n\n<p>Notice that if you try to remove a regular table with the <code>DROP TEMPORARY TABLE<\/code> statement, you will get an error message saying that the table that you are trying to drop is unknown.<\/p>\n\n\n\n<p>If you develop an application that uses connection pooling or persistent connections, it is not guaranteed that the temporary tables are removed automatically when your application is terminated. <\/p>\n\n\n\n<p>Because the database connection that the application uses may be still open and placed in a connection pool for other clients to reuse later. <\/p>\n\n\n\n<p>Therefore, it is a good practice to always remove the temporary tables whenever you are no longer use them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checking if a temporary table exists<\/h2>\n\n\n\n<p>MySQL does not provide a function or statement to directly check if a temporary table exists. <\/p>\n\n\n\n<p>However, you can create a <a href=\"https:\/\/www.mysqltutorial.org\/mysql-stored-procedure\/\">stored procedure<\/a> that checks if a temporary table exists or not as follows:<\/p>\n\n\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\">DELIMITER \/\/\n<span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">PROCEDURE<\/span> check_table_exists(table_name <span class=\"hljs-built_in\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>)) \n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">DECLARE<\/span> CONTINUE <span class=\"hljs-keyword\">HANDLER<\/span> <span class=\"hljs-keyword\">FOR<\/span> <span class=\"hljs-keyword\">SQLSTATE<\/span> <span class=\"hljs-string\">'42S02'<\/span> <span class=\"hljs-keyword\">SET<\/span> @err = <span class=\"hljs-number\">1<\/span>;\n    <span class=\"hljs-keyword\">SET<\/span> @err = <span class=\"hljs-number\">0<\/span>;\n    <span class=\"hljs-keyword\">SET<\/span> @table_name = table_name;\n    <span class=\"hljs-keyword\">SET<\/span> @sql_query = <span class=\"hljs-keyword\">CONCAT<\/span>(<span class=\"hljs-string\">'SELECT 1 FROM '<\/span>,@table_name);\n    <span class=\"hljs-keyword\">PREPARE<\/span> stmt1 <span class=\"hljs-keyword\">FROM<\/span> @sql_query;\n    IF (@err = 1) THEN\n        <span class=\"hljs-keyword\">SET<\/span> @table_exists = <span class=\"hljs-number\">0<\/span>;\n    ELSE\n        <span class=\"hljs-keyword\">SET<\/span> @table_exists = <span class=\"hljs-number\">1<\/span>;\n        <span class=\"hljs-keyword\">DEALLOCATE<\/span> <span class=\"hljs-keyword\">PREPARE<\/span> stmt1;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n<span class=\"hljs-keyword\">END<\/span> \/\/\nDELIMITER ;<\/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>\n\n\n<p>In this procedure, we try to select data from a temporary table. If the temporary table exists, the <code>@table_exists<\/code> variable is set to 1, otherwise, it is set to 0.<\/p>\n\n\n\n<p>This statement calls the <code>check_table_exists<\/code> stored procedure to check if the temporary table <code>credits<\/code>&nbsp;exists:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">CALL<\/span> check_table_exists(<span class=\"hljs-string\">'credits'<\/span>);\n<span class=\"hljs-keyword\">SELECT<\/span> @table_exists;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"106\" height=\"36\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/08\/MySQL-check-temporary-table-exists.png\" alt=\"\" class=\"wp-image-7821\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL automatically deletes all temporary tables once the session is ended.<\/li>\n\n\n\n<li>Use the <code>CREATE TEMPORARY TABLE<\/code> statement to create a temporary table.<\/li>\n\n\n\n<li>Use the <code>DROP TEMPORARY TABLE<\/code> statement to drop a temporary table.<\/li>\n<\/ul>\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=\"2153\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-temporary-table\/\"\n\t\t\t\tdata-post-title=\"MySQL Temporary Tables\"\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=\"2153\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-temporary-table\/\"\n\t\t\t\tdata-post-title=\"MySQL Temporary Tables\"\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>This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary tables.<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":174,"menu_order":43,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2153","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Temporary Tables<\/title>\n<meta name=\"description\" content=\"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary 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.mysqltutorial.org\/mysql-temporary-table\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL Temporary Tables\" \/>\n<meta property=\"og:description\" content=\"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary tables.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-23T13:50:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png\" \/>\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\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/\",\"name\":\"MySQL Temporary Tables\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/MySQL-Temporary-Table-Example.png\",\"datePublished\":\"2013-05-08T09:31:26+00:00\",\"dateModified\":\"2023-10-23T13:50:21+00:00\",\"description\":\"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary tables.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/MySQL-Temporary-Table-Example.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2018\\\/07\\\/MySQL-Temporary-Table-Example.png\",\"width\":346,\"height\":219},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-temporary-table\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL Basics\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-basics\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL Temporary Tables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Temporary Tables","description":"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary 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.mysqltutorial.org\/mysql-temporary-table\/","og_locale":"en_US","og_type":"article","og_title":"MySQL Temporary Tables","og_description":"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary tables.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/","og_site_name":"MySQL Tutorial","article_modified_time":"2023-10-23T13:50:21+00:00","og_image":[{"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/","url":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/","name":"MySQL Temporary Tables","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png","datePublished":"2013-05-08T09:31:26+00:00","dateModified":"2023-10-23T13:50:21+00:00","description":"This tutorial discusses MySQL temporary tables and shows you step-by-step how to create, use, and drop temporary tables.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2018\/07\/MySQL-Temporary-Table-Example.png","width":346,"height":219},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-temporary-table\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL Basics","item":"https:\/\/www.mysqltutorial.org\/mysql-basics\/"},{"@type":"ListItem","position":3,"name":"MySQL Temporary Tables"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2153\/revisions"}],"predecessor-version":[{"id":11609,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/2153\/revisions\/11609"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/174"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}