{"id":171955,"date":"2023-10-15T08:35:59","date_gmt":"2023-10-15T07:35:59","guid":{"rendered":"https:\/\/liora.io\/en\/?p=171955"},"modified":"2026-02-06T08:54:44","modified_gmt":"2026-02-06T07:54:44","slug":"sql-insert-into-insert-data-with-this-sql-query","status":"publish","type":"post","link":"https:\/\/liora.io\/en\/sql-insert-into-insert-data-with-this-sql-query","title":{"rendered":"SQL INSERT INTO: Insert data with this SQL query"},"content":{"rendered":"<p><strong>To insert data into your SQL table, you can use the SQL INSERT INTO query. But how does it work? That&#8217;s what we&#8217;re going to look at in this article.<\/strong><\/p>\t\t\n\t\t\t<h3>What is an SQL INSERT INTO request?<\/h3>\t\t\n\t\t<p><strong>SQL INSERT INTO<\/strong> is one of the most <a href=\"https:\/\/liora.io\/en\/sql-delete-how-do-i-use-this-query\">commonly used commands in the SQL language.<\/a> And with good reason: this query allows you to integrate new records into your database. This can be one or more rows, depending on your needs.<\/p><p><strong>Good to know:<\/strong> INSERT INTO is the command to use for all database management systems. Whether you&#8217;re using Oracle, Mysql, Transact-<a href=\"https:\/\/liora.io\/en\/sql-developer-what-is-it-whats-it-for\">SQL, etc.<\/a><\/p>\t\t\n\t\t\t<h3>How to use the SQL query INSERT INTO?<\/h3>\t\t\n\t\t<p>INSERT INTO can be used to insert one or more rows into your table. But it&#8217;s also possible to use this command in more complex queries. In this article, we&#8217;ll take a look at some of these applications.<\/p>\t\t\n\t\t\t<h4>Insert a line<\/h4>\t\t\n\t\t<p>There are two ways of doing this.<\/p><p>1\u00ba You can insert a line by specifying all the columns. In this case, the syntax is as follows:<\/p><p><strong>INSERT INTO table VALUES (&#8216;value 1&#8217;, &#8216;value 2&#8217;, &#8230;)<\/strong><\/p><p>If you choose this option, be sure to respect the order of the columns. The <a href=\"https:\/\/liora.io\/en\/database-what-is-it\">database<\/a> management system interprets <a href=\"https:\/\/liora.io\/en\/sql-joins-everything-you-need-to-know-about\">SQL queries<\/a> according to the information you give it. So if you don&#8217;t need to record new values for certain columns, you&#8217;ll need to specify &#8220;NULL&#8221; (instead of value 1,2&#8230;).<\/p><p>The advantage is that you don&#8217;t need to write the name of each limit. This greatly reduces typing errors.<\/p><p>2\u00ba You can specify only those columns for which you wish to integrate new data. To do this, use the following syntax:<\/p><p><strong>INSERT INTO<\/strong> table (column-name_1, column-name_2, &#8230;)<br>VALUES (&#8216;value 1&#8217;, &#8216;value 2&#8217;, &#8230;)<\/p><p>Here, column order is no longer as important. Be careful, however, with the order of values. They must correspond to the columns to which they are assigned.<\/p>\t\t\n\t\t\t<h4>Insert several lines<\/h4>\t\t\n\t\t<p>Inserting several lines is often necessary to enrich your table.<\/p><p>To help you understand, here&#8217;s a concrete example of a Customer file to which you want to add the contact details of several customers.<\/p><p>Here&#8217;s the query:<\/p><p>INSERT INTO customer (first name, last name, city, email)<br>VALUES<br>(&#8216;Justine&#8217;, &#8216;Martin&#8217;, &#8216;Paris&#8217;, &#8216;justinemartin@gmail.com&#8217; ),<br>(&#8216;Thomas&#8217;, &#8216;Durant&#8217;, &#8216;Bordeaux&#8217;, &#8216;tomtom@sfr.fr&#8217;),<br>(&#8216;Marie&#8217;, &#8216;Leroy&#8217;, &#8216;Angers&#8217;, &#8216;marieleroy@laposte.net&#8217;),<br>(&#8216;Vanessa&#8217;, &#8216;Savary&#8217;, &#8216;Marseille&#8217;, &#8216;vanessa13@gmail.com&#8217;)es<\/p>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/\">Learn how to use INSERT INTO<\/a><\/div><\/div>\n\n\t\t<p>Use the INSERT INTO command to integrate the following data into your table.<\/p>\t\t\n\t\t\t<style type=\"text\/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-8806{background-color:#6434fc;border-color:inherit;color:#efefef;text-align:center;vertical-align:top}\n.tg .tg-baqh{text-align:center;vertical-align:top}\n.tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}\n.tg .tg-mw77{background-color:#6434fc;color:#efefef;text-align:center;vertical-align:top}\n<\/style>\n<table style=\"undefined;table-layout: fixed; width: 500px\">\n<colgroup>\n<col style=\"width: 125px\">\n<col style=\"width: 100px\">\n<col style=\"width: 100px\">\n<col style=\"width: 150px\">\n<\/colgroup>\n<thead>\n  <tr>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>City<\/th>\n    <th>Email<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>Justin<\/td>\n    <td>Martin<\/td>\n    <td>Paris<\/td>\n    <td>justinemartin@gmail.com<\/td>\n  <\/tr>\n  <tr>\n    <td>Thomas <\/td>\n    <td>Durant<\/td>\n    <td>Bordeaux<\/td>\n    <td>tomtom@sfr.fr<\/td>\n  <\/tr>\n  <tr>\n    <td>Marie<\/td>\n    <td>Leroy<\/td>\n    <td>Angers<\/td>\n    <td>marieleroy@laposte.net<\/td>\n  <\/tr>\n  <tr>\n    <td>Vanessa<\/td>\n    <td>Savary<\/td>\n    <td>Marseille<\/td>\n    <td>vanessa13@gmail.com<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\t\t\n\t\t\t<h4>Copy data from another table<\/h4>\t\t\n\t\t<p>By combining several queries, you can also copy data from an A array to a table.<\/p><p>To do this, use the following syntax:<\/p><p>INSERT INTO my_table_1 SELECT column_1,column_2,column_2 FROM my_table_2 WHERE conditions<\/p><p>Let&#8217;s take an example:<\/p><p>You have two tables. The first corresponds to a &#8220;customer&#8221; file:<\/p>\t\t\n\t\t\t<style type=\"text\/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-8806{background-color:#6434fc;border-color:inherit;color:#efefef;text-align:center;vertical-align:top}\n.tg .tg-baqh{text-align:center;vertical-align:top}\n.tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}\n.tg .tg-mw77{background-color:#6434fc;color:#efefef;text-align:center;vertical-align:top}\n<\/style>\n<table style=\"undefined;table-layout: fixed; width: 500px\">\n<colgroup>\n<col style=\"width: 125px\">\n<col style=\"width: 100px\">\n<col style=\"width: 100px\">\n<col style=\"width: 150px\">\n<\/colgroup>\n<thead>\n  <tr>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>City<\/th>\n    <th>Email<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>Justin<\/td>\n    <td>Martin<\/td>\n    <td>Paris<\/td>\n    <td>justinemartin@gmail.com<\/td>\n  <\/tr>\n  <tr>\n    <td>Thomas <\/td>\n    <td>Durant<\/td>\n    <td>Bordeaux<\/td>\n    <td>tomtom@sfr.fr<\/td>\n  <\/tr>\n  <tr>\n    <td>Marie<\/td>\n    <td>Leroy<\/td>\n    <td>Angers<\/td>\n    <td>marieleroy@laposte.net<\/td>\n  <\/tr>\n  <tr>\n    <td>Vanessa<\/td>\n    <td>Savary<\/td>\n    <td>Marseille<\/td>\n    <td>vanessa13@gmail.com<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\n\t\t<p>And the second, to a &#8220;Prospecting&#8221; file:<\/p>\t\t\n\t\t\t<style type=\"text\/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-8806{background-color:#6434fc;border-color:inherit;color:#efefef;text-align:center;vertical-align:top}\n.tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}\n<\/style>\n<table style=\"undefined;table-layout: fixed; width: 525px\">\n<colgroup>\n<col style=\"width: 25px\">\n<col style=\"width: 125px\">\n<col style=\"width: 100px\">\n<col style=\"width: 100px\">\n<col style=\"width: 150px\">\n<\/colgroup>\n<thead>\n  <tr>\n    <th>ID<\/th>\n    <th>Pr\u00e9nom<\/th>\n    <th>Nom<\/th>\n    <th>Ville<\/th>\n    <th>Email<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>1<\/td>\n    <td>Jean<\/td>\n    <td>Bernad<\/td>\n    <td>Valenciennes<\/td>\n    <td>jbernard@gmail.com<\/td>\n  <\/tr>\n  <tr>\n    <td>2<\/td>\n    <td>Thomas <\/td>\n    <td>Castaing<\/td>\n    <td>Nantes<\/td>\n    <td>thomas.castaing@orange.fr<\/td>\n  <\/tr>\n  <tr>\n    <td>3<\/td>\n    <td>Antoine<\/td>\n    <td>Dupond<\/td>\n    <td>Paris<\/td>\n    <td>Antwan@laposte.net<\/td>\n  <\/tr>\n  <tr>\n    <td>4<\/td>\n    <td>Virginie<\/td>\n    <td>Pavard<\/td>\n    <td>Lyon<\/td>\n    <td>V.pavard@gmail.com<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\t\t\n\t\t<p>Having converted a prospect (Jean Bernard), you want to transfer him to your customer file.<\/p><p>Here&#8217;s the query:<\/p><p>INSERT INTO Customer SELECT (first name, last name, city, email) FROM prospect WHERE id = 1<\/p><p>And the result:<\/p>\t\t\n\t\t\t<style type=\"text\/css\">\n.tg  {border-collapse:collapse;border-spacing:0;}\n.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;\n  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}\n.tg .tg-8806{background-color:#6434fc;border-color:inherit;color:#efefef;text-align:center;vertical-align:top}\n.tg .tg-baqh{text-align:center;vertical-align:top}\n.tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}\n<\/style>\n<table style=\"undefined;table-layout: fixed; width: 500px\">\n<colgroup>\n<col style=\"width: 125px\">\n<col style=\"width: 100px\">\n<col style=\"width: 100px\">\n<col style=\"width: 150px\">\n<\/colgroup>\n<thead>\n  <tr>\n    <th>First Name<\/th>\n    <th>Last Name<\/th>\n    <th>City<\/th>\n    <th>Email<\/th>\n  <\/tr>\n<\/thead>\n<tbody>\n  <tr>\n    <td>Justin<\/td>\n    <td>Martin<\/td>\n    <td>Paris<\/td>\n    <td>justinemartin@gmail.com<\/td>\n  <\/tr>\n  <tr>\n    <td>Thomas <\/td>\n    <td>Durant<\/td>\n    <td>Bordeaux<\/td>\n    <td>tomtom@sfr.fr<\/td>\n  <\/tr>\n  <tr>\n    <td>Marie<\/td>\n    <td>Leroy<\/td>\n    <td>Angers<\/td>\n    <td>marieleroy@laposte.net<\/td>\n  <\/tr>\n  <tr>\n    <td>Vanessa<\/td>\n    <td>Savary<\/td>\n    <td>Marseille<\/td>\n    <td>vanessa13@gmail.com<\/td>\n  <\/tr>\n  <tr>\n    <td>Jean<\/td>\n    <td>Bernard<\/td>\n    <td>Valenciennes<\/td>\n    <td>jbernard@gmail.com<\/td>\n  <\/tr>\n<\/tbody>\n<\/table>\n\t\t\t<h3>Develop your SQL skills with Liora<\/h3>\t\t\n\t\t<p>Manipulating relational data doesn&#8217;t just mean adding new information. It&#8217;s also possible to delete, modify, update and so on. For all these actions, there are a multitude of <a href=\"https:\/\/liora.io\/en\/sql-vs-nosql\">SQL queries<\/a>. If you want to know them all, data training is more than necessary. That&#8217;s why we&#8217;ve developed Liora. We offer a range of industry-specific training courses to help you develop your skills.<\/p>\t\t\n\t\t\t\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex is-content-justification-center\"><div class=\"wp-block-button \"><a class=\"wp-block-button__link wp-element-button \" href=\"\/en\/courses\/data-ai\/#\">Start your SQL training<\/a><\/div><\/div>\n\n\t\t\t<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"FAQPage\",\n  \"mainEntity\": [{\n    \"@type\": \"Question\",\n    \"name\": \"What is UPDATE SQL?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"The SQL UPDATE command is used to update data within a table. This is essential if you want to maintain a database with up-to-date, reliable information. Since data quality is one of the biggest challenges facing data scientists, UPDATE is one of the most common SQL queries.\"\n    }\n  },{\n    \"@type\": \"Question\",\n    \"name\": \"How do I use the UPDATE SQL command?\",\n    \"acceptedAnswer\": {\n      \"@type\": \"Answer\",\n      \"text\": \"To understand it better, let's go back over its main attributes: The SET clause: this defines what you're going to replace existing data with. Here, only the columns to be modified need be specified. All other columns retain their current values. The WHERE clause: this is used to specify where the changes are to be made.\"\n    }\n  }]\n}\n<\/script<\/script>","protected":false},"excerpt":{"rendered":"<p>To insert data into your SQL table, you can use the SQL INSERT INTO query. But how does it work? That&#8217;s what we&#8217;re going to look at in this article. What is an SQL INSERT INTO request? SQL INSERT INTO is one of the most commonly used commands in the SQL language. And with good [&hellip;]<\/p>\n","protected":false},"author":76,"featured_media":171956,"comment_status":"open","ping_status":"open","sticky":false,"template":"elementor_theme","format":"standard","meta":{"_acf_changed":false,"editor_notices":[],"footnotes":""},"categories":[2434],"class_list":["post-171955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cloud-dev"],"acf":[],"_links":{"self":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/171955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/users\/76"}],"replies":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/comments?post=171955"}],"version-history":[{"count":1,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/171955\/revisions"}],"predecessor-version":[{"id":206320,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/posts\/171955\/revisions\/206320"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media\/171956"}],"wp:attachment":[{"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/media?parent=171955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liora.io\/en\/wp-json\/wp\/v2\/categories?post=171955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}