In this MariaDB tutorial, we will discuss using the MariaDB Insert Into Select statement and look at several examples. There are lists of the topic that comes under discussion:
- MariaDB Insert Into Select
- MariaDB Insert Into Select Auto_Increment
- MariaDB Insert Into Select on Duplicate Key Update
- MariaDB Insert Into Select Example
- MariaDB Insert Into Select Count
- MariaDB Insert Into Select Distinct
- MariaDB Insert into Select Group By
- MariaDB Insert Into Select Having
- MariaDB Insert Into Select JSON
- MariaDB Insert Into Select Multiple Columns
- MariaDB Insert Into Select Not Working
- MariaDB Insert Into Select Order By
- MariaDB Insert Into Select Primary Key
- MariaDB Insert Into Select Year
MariaDB Insert Into Select
We’ll go through the MariaDB Insert Into Select statement and how to use it to put a query’s result set into a table.
In MariaDB, the value list of an INSERT statement could be either specific values or the query result. The following query will demonstrate the code of applying the INSERT INTO SELECT statement in MariaDB:
SYNTAX:
INSERT INTO SELECT YOUR_TABLE_NAME(COLUMN_NAME_1,COLUMN_NAME_2,COLUMN_NAME_N)
SELECT COLUMN_NAME FROM YOUR_TABLE_NAME
WHERE [CONDITIONS];
The syntax explanation:
- To begin, give the table a name as well as a set of columns into which we wish to insert data.
- Second, use the MariaDB SELECT command to acquire a result set with columns matching the COLUMN_NAME_1, COLUMN_NAME_2 and COLUMN_NAME_N columns in the table.
The INSERT INTO SELECT statement in MariaDB is useful for transferring from one table to another or combining data from numerous tables into a single table. First, let’s a look at the STATES_OF_USA table by the following query:
SELECT * FROM STATES_OF_USA;
The MariaDB SELECT statement is used to retrieve all records from the STATES_OF_USA table.

For inserting new rows from one table into a table by using the CREATE TABLE statement: Here is an illustrated example below:
EXAMPLE:
CREATE TABLE MINI_WALMART(
ID INT PRIMARY KEY,
first_name VARCHAR(20),
LAST_NAME VARCHAR(30),
AGE INT,
CUSTOMER_DATE DATE,
IP_ADDRESS VARCHAR(30));
Example of the INSERT INTO SELECT statement from one table called MINI_WALMART from the WALMART_CUSTOMER table by the following query:
EXAMPLE:
INSERT INTO MINI_WALMART(ID,FIRST_NAME,LAST_NAME)
SELECT ID,FIRST_NAME,LAST_NAME
FROM WALMART_CUSTOMER
WHERE
ID<=20;
SELECT * FROM MINI_WALMART;
In this query, we first built a thing called MINI_WALMART, which contains duplicate fields and has the same name as the CREATE TABLE command.
In the INSERT INTO statement, we have used the ID, FIRST_NAME, and LAST_NAME columns from WALMART_CUSTOMER with the same column names. And sent the records of the ID till 20 based on the WHERE condition.
If we want to check the new records added to the ID, FIRST_NAME and LAST_NAME columns then use the SELECT statement for the MINI_WALMART table.

Read: MariaDB COUNT Function
MariaDB Insert Into Select Auto_Increment
In this section, we will use the AUTO_INCREMENT constraint of the column by using the INSERT INTO SELECT statement in MariaDB
Before we jump into the example, we need to create a new table called MINI_USA_STATES which will insert new rows from the STATES_OF_USA table in the following query:
EXAMPLE:
CREATE TABLE MINI_USA_STATES(
STATE_ID INT PRIMARY KEY AUTO_INCREMENT);
INSERT INTO MINI_USA_STATES(STATE_ID)
SELECT STATE_ID FROM STATES_OF_USA
WHERE STATE_ID<=50;
SELECT * FROM MINI_USA_STATES;
- In the first query, we created a table called MINI_USA_STATES for the column STATE_ID with the AUTO_INCREMENT constraint in it.
- In the final query, we insert new records of the STATE_ID column from the MINI_USA_STATES to the STATES_OF_USA table by using the WHERE condition.
- In the WHERE condition, the STATE_ID column gets the values till 50 with the greater than or equal to the operator.
- If we want to check the records of the STATE_ID column has been sent from the STATES_OF_USA table.
- Then use the SELECT statement to retrieve all records of the STATE_ID column on the MINI_USA_STATES table.

Read: MariaDB JSON Data Type
MariaDB Insert Into Select on Duplicate Key Update
In this section, we will learn and understand how to use the INSERT INTO SELECT statement on the DUPLICATE KEY UPDATE clause in MariaDB. And we will explain it with the help of an example.
The MariaDB INSERT ON DUPLICATE KEY UPDATE statement is an extension of the INSERT statement. If we add additional rows to the table and the UNIQUE KEY and PRIMARY KEY are duplicated, an error will occur.
Here is the syntax of the INSERT INTO SELECT statement with the ON DUPLICATE KEY UPDATE clause in the following query:
SYNTAX:
INSERT INTO NEW_TABLE_NAME(COLUMN_LIST)
SELECT EXPRESSION FROM TABLE_NAME
ON DUPLICATE KEY UPDATE
COLUMN_NAME_1=NEW_VALUE_1,
COLUMN_NAME_2= NEW_VALUE_2;
Let’s have a look at the demonstrated example of the INSERT INTO SELECT statement with the ON DUPLICATE KEY UPDATE clause by the following query:
EXAMPLE:
CREATE TABLE USA_CONSUMER_LIST(
ID INT,
first_name VARCHAR(20),
LAST_NAME VARCHAR(30),
EMAIL VARCHAR(40),
PRICE INT);
INSERT INTO USA_CONSUMER_LIST(ID,FIRST_NAME,LAST_NAME,EMAIL,PRICE)
SELECT ID,FIRST_NAME,LAST_NAME,EMAIL,PRICE FROM CUSTOMER_LIST
ON DUPLICATE KEY UPDATE
FIRST_NAME='JOHN',
PRICE=48;
SELECT * FROM USA_CONSUMER_LIST;
In the first query, we created another table called USA_CONSUMER_LIST by using the CREATE TABLE statement. The main reason to create another table is that it will insert a new record from the CUSTOMER_LIST table.
In the second query, we have inserted new records in all columns of the USA_CONSUMER_LIST table by using the INSERT INTO statement. In the SELECT statement, it will select all records from the CUSTOMER_LIST table and sent them to the USA_CONSUMER_LIST table.
In the end, we have used the ON DUPLICATE KEY UPDATE statement, to update the FIRST_NAME column as JOHN and PRICE as 44.
The main reason to use the ON DUPLICATE KEY UPDATE is that it will remove the error for the primary key column and unique key column of the table if it contains it in the table.
If we want to check that the new records have been inserted into the USA_CUSTOMER_LIST table. Then we will use the SELECT statement to retrieve all records for the result set.

Read: Load files into MariaDB
MariaDB Insert Into Select Example
Here we will use an illustrated example of the INSERT INTO SELECT statement in MariaDB and try to explain it in detail.
First, we will create another table called USA_PEOPLE to insert new records from the PERSON_DETAIL table. Here is the example of the INSERT INTO SELECT statement with the CREATE TABLE statement in the following query:
EXAMPLE:
CREATE TABLE USA_PEOPLE(
JUST_ID INT,
PERSON_NAME VARCHAR(20));
INSERT INTO USA_PEOPLE(JUST_ID,PERSON_NAME)
SELECT JUST_ID,PERSON_NAME FROM person_detail
WHERE JUST_ID<=40;
SELECT * FROM USA_PEOPLE;
In the first query, we created a table called USA_PEOPLE to insert new records for JUST_ID and PERSON_NAME columns from the PERSON_DETAIL table by using the CREATE TABLE statement.
In the second query, new records have been inserted for the JUST_ID and PERSON_NAME columns with the help of the INSERT INTO statement.
And to select all records from the JUST_ID and PERSON_NAME columns of the PERSON_DETAIL table by using the WHERE condition. In the WHERE condition, we have collected the records till 40 of the JUST_ID column.
If we want to check the new records inserted into the JUST_ID and PERSON_NAME columns of the USA_PEOPLE table, then use the SELECT statement.

Read: MariaDB Reserved Words
MariaDB Insert Into Select Count
In this section, we will use the INSERT INTO SELECT statement with the MariaDB COUNT function in the query and which is explained with the help of an illustrated example.
In MariaDB, the COUNT function is used to return a count of an expression or column_name from the query.
First, we will create another table called USA_PERSON_DETAIL which will insert new records for the JUST_ID, PERSON_NAME, and MALE_FEMALE columns of the PERSONAL_DETAIL table by using the CREATE TABLE statement.
And it is shown in the below query with the INSERT INTO statement and the COUNT function:
EXAMPLE:
CREATE TABLE USA_PERSON_DETAIL(
JUST_ID INT,
PERSON_NAME VARCHAR(20),
MALE_FEMALE VARCHAR(10));
INSERT INTO USA_PERSON_DETAIL(JUST_ID,PERSON_NAME,MALE_FEMALE)
SELECT COUNT(JUST_ID),PERSON_NAME,MALE_FEMALE
FROM PERSONAL_DETAIL
WHERE JUST_ID<=10;
SELECT * FROM USA_PERSON_DETAIL;
In the first query, we created a table called USA_PERSON_DETAIL by using the CREATE TABLE statement and new columns added are JUST_ID, PERSON_NAME, and MALE_FEMALE.
In the second query, the INSERT INTO statement is used to insert new records in the JUST_ID, PERSON_NAME, and MALE_FEMALE columns of the USA_PERSON_DETAIL table.
While using the SELECT statement, we have used the COUNT function on the JUST_ID column. And retrieved records from the PERSON_NAME and MALE_FEMALE columns on the PERSONAL_DETAIL table based on the WHERE condition.
In the WHERE condition, if the JUST_ID column is equal to or greater than 10 then the condition is TRUE.
Then it will retrieve one record to the USA_PERSON_DETAIL table from the PERSONAL_DETAIL column. If we want to check the record has been retrieved in the USA_PERSON_DETAIL table, then use the SELECT statement.

Read: MariaDB Median
MariaDB Insert Into Select Distinct
We will learn and discuss how to use the MariaDB INSERT INTO SELECT statement with the DISTINCT function in the query and which is explained with the help of an illustrated example.
In MariaDB, the DISTINCT function is used to select duplicate values from the SELECT statement. Let’s see an illustrated example of the INSERT INTO SELECT statement with the COUNT function by the following query:
EXAMPLE:
CREATE TABLE USA_PERSON_DETAIL(
JUST_ID INT,
PERSON_NAME VARCHAR(20),
MALE_FEMALE VARCHAR(10));
INSERT INTO USA_PERSON_DETAIL(JUST_ID,PERSON_NAME,MALE_FEMALE)
SELECT DISTINCT(JUST_ID),PERSON_NAME,MALE_FEMALE
FROM PERSONAL_DETAIL
WHERE JUST_ID<=10;
SELECT * FROM USA_PERSON_DETAIL;
- In the first query, we created a table called the USA_PERSON_DETAIL by using the CREATE TABLE statement.
- In the second query, we used the DISTINCT function on the JUST_ID column and retrieved records from the PERSON_NAME and the MALE_FEMALE column from the PERSONAL_DETAIL table.
- In the WHERE condition, the JUST_ID column will get records of the 10 rows. If the condition gets TRUE then we will use the SELECT statement.
- If we want to retrieve all records from the USA_PERSON_DETAIL table, then use the SELECT statement.

Read: MariaDB Drop Index
MariaDB Insert into Select Group By
Here we will understand and learn how to use the MariaDB INSERT INTO SELECT statement with the GROUP BY clause in the query and which is explained with the help of an illustrated example.
The group by clause in MariaDB divides a result’s rows into categories. The aggregate functions count(), min(), max(), sum(), and avg() are frequently used with the group by function to obtain attributes of groups.
For example, the number of elements (count), the total of values (sum), the maximum element (max), the minimum element (min), and the average of elements (avg).
First, we will create a table called MINI_USA_CUSTOMER which will insert new records of the ID, FIRST_NAME, and LAST_NAME columns from the CUSTOMER_LIST table by using the CREATE TABLE statement.
Here is an illustrated example of the INSERT INTO SELECT statement with the GROUP BY clause in the following query:
EXAMPLE:
CREATE TABLE MINI_USA_CUSTOMER(
ID INT,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30));
INSERT INTO MINI_USA_CUSTOMER(ID,FIRST_NAME,LAST_NAME)
SELECT ID,first_name,LAST_NAME
FROM customer_list
WHERE ID<=10
GROUP BY first_name;
SELECT * FROM MINI_USA_CUSTOMER;
In the first query, we created a table called MINI_USA_CUSTOMER by using the CREATE TABLE statement. In the MINI_USA_CUSTOMER table, we have created columns like ID, FIRST_NAME, and LAST_NAME with data types INT and VARCHAR.
In the second query, we have inserted records from the CUSTOMER_LIST table for the ID, FIRST_NAME, and LAST_NAME columns into the MINI_USA_CUSTOMER table by using the INSERT INTO SELECT statement.
In the WHERE condition, we will retrieve records till 10 on the ID column. If the WHERE condition gets TRUE, then we will group them based on the FIRST_NAME column in the MINI_USA_CUSTOMER table by using the GROUP BY clause.
If we want to check that the new records have been inserted into the MINI_USA_CUSTOMER table, then use the SELECT statement for the result set.

Read: MariaDB Greatest Function
MariaDB Insert Into Select Having
In this sub-topic, we will discuss and learn how to use the MariaDB INSERT INTO SELECT statement with the HAVING clause in the query and which is explained with the help of an illustrated example.
The MariaDB HAVING clause is used in conjunction with the GROUP BY clause to limit the returned rows to those that meet the condition. Let’s see an example of the INSERT INTO SELECT statement with the HAVING clause in the below following query:
EXAMPLE:
CREATE TABLE USA_FAZZRO(
ID INT,
FULL_NAME VARCHAR(40),
JOINING_DATE DATE);
INSERT INTO USA_FAZZRO(ID, FULL_NAME,JOINING_DATE)
SELECT ID,FULL_NAME,JOINING_DATE FROM FAZZRO_COMPANY
GROUP BY FULL_NAME
HAVING JOINING_DATE;
SELECT * FROM USA_FAZZRO;
In the first query, we created a table called USA_FAZZRO which will insert records from another table called FAZZRO_COMPANY, and it was created by CREATE TABLE statement.
In the second query, we have inserted new records into the USA_FAZZRO table by using the INSERT INTO statement. And selected the records of the ID, FULL_NAME, and JOINING_DATE columns from the FAZZRO_COMPANY into the USA_FAZZRO table by using the SELECT statement.
In the SELECT statement, it grouped the records of the FULL_NAME column having the JOINING_DATE column by using the GROUP BY clause and HAVING clause.
If we want to check whether the records have been sent to the USA_FAZZRO table or not. Then use the SELECT statement to retrieve all records from the USA_FAZZRO table for the result set.

Read: MariaDB Between + Examples
MariaDB Insert Into Select JSON
Here we will understand and learn how to use the MariaDB INSERT INTO SELECT statement with the JSON data type in the query and which is explained with the help of an illustrated example.
MariaDB’s JSON data type is a replacement for LONGTEXT, which was designed to work with MySQL’s JSON data type. Because it violates the SQL standard, MariaDB supports the JSON data format as a LONGTEXT instead, and MariaDB’s benchmarks show that efficiency is at least comparable.
Let’s see an example of the INSERT INTO SELECT statement with the JSON data type in the following query:
EXAMPLE:
CREATE TABLE MariaDB_JSON(
USER_NAME VARCHAR(30),
JSON_VALUE LONGTEXT);
INSERT INTO MariaDB_JSON(USER_NAME,JSON_VALUE)
SELECT USER_NAME,JSON_VALUE
FROM JSON_DEMO;
SELECT * FROM MariaDB_JSON;
- In the first query, we have created another table called MariaDB_JSON which will insert all records from the JSON_DEMO table. And it is used by the CREATE TABLE statement.
- In the second query, the columns like USER_NAME and JSON_VALUE of the MariaDB_JSON table which is used by the INSERT INTO statement.
- And it selected all the records of the USER_NAME and JSON_VALUE columns of the JSON_DEMO table from which all records will be transferred to the MariaDB_JSON table by using the SELECT statement.
- If we want to check that all records have been retrieved from the MariaDB_JSON table then we will use the SELECT statement.

Read: MariaDB Not Equal Operator
MariaDB Insert Into Select Multiple Columns
Here we will use an example for the MariaDB INSERT INTO SELECT statement for multiple columns in the query.
EXAMPLE:
CREATE TABLE USA_WALMART_COMPANY(
ID INT,
first_name VARCHAR(20),
LAST_NAME VARCHAR(30),
CUSTOMER_DATE DATE,
IP_ADDRESS VARCHAR(20));
INSERT INTO USA_WALMART_COMPANY(ID,FIRST_NAME,LAST_NAME,CUSTOMER_DATE,IP_ADDRESS)
SELECT ID,FIRSt_NAME, LAST_NAME,CUSTOMER_DATE,IP_ADDRESS
FROM WALMART_CUSTOMER;
SELECT * FROM USA_WALMART_COMPANY;
- In the preceding query, we have created another table called USA_WALMART_COMPANY which will retrieve records from the WALMART_CUSTOMER table.
- And it’s done by using the CREATE TABLE statement.
- In the second query, we have inserted records of all the columns from the WALMART_CUSTOMER table to USA_WALMART_COMPANY by using the INSERT INTO SELECT statement.
- If we want to check that all records have been inserted into a new table called USA_WALMART_COMPANY table, then use the SELECT statement.

Read: MariaDB Delete From Statement
MariaDB Insert Into Select Not Working
Here, we will understand and know why the MariaDB INSERT INTO SELECT statement is not working in the query and which is explained with the help of an illustrated example.
In MariaDB, the INSERT INTO SELECT statement is not working only due to technical/ logical errors or a query that has not been made by the user properly. First, let’s see an example of the MariaDB INSERT INTO SELECT statement is not working in the below query:
ERROR EXAMPLE:
CREATE TABLE USA_WALMART_COMPANY(
ID INT,
first_name VARCHAR(20),
LAST_NAME VARCHAR(30),
CUSTOMER_DATE DATE,
IP_ADDRESS VARCHAR(20));
INSERT INTO USA_WALMART_COMPANY(ID,LAST_NAME,CUSTOMER_DATE,IP_ADDRESS)
SELECT ID, first_name, LAST_NAME,CUSTOMER_DATE,IP_ADDRESS
FROM walmart_customer;
SELECT * FROM USA_WALMART_COMPANY;
The first query of the MariaDB CREATE TABLE statement has been executed. The second query of the INSERT INTO SELECT statement has not been executed due to one of the columns FIRST_NAME being missing from the query. So, due to which error has been issued.

REAL EXAMPLE:
CREATE TABLE USA_WALMART_COMPANY(
ID INT,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30),
CUSTOMER_DATE DATE,
IP_ADDRESS VARCHAR(20));
INSERT INTO USA_WALMART_COMPANY(ID,FIRST_NAME,LAST_NAME,CUSTOMER_DATE,IP_ADDRESS)
SELECT ID,FIRST_NAME,LAST_NAME,CUSTOMER_DATE,IP_ADDRESS
FROM WALMART_CUSTOMER;
SELECT * FROM USA_WALMART_COMPANY;
- In the preceding query, we have created another table called USA_WALMART_COMPANY which will retrieve records from the WALMART_CUSTOMER table. And it’s done by using the CREATE TABLE statement.
- In the second query, we have inserted records of all the columns from the WALMART_CUSTOMER table to USA_WALMART_COMPANY by using the INSERT INTO SELECT statement.
- If we want to check that all records have been inserted into a new table called USA_WALMART_COMPANY table, then use the SELECT statement.

Read: MariaDB Rename Table
MariaDB Insert Into Select Order By
We will discuss and learn how to use the MariaDB INSERT INTO SELECT statement with the ORDER BY clause in the query and which is explained with a demonstrated example.
In MariaDB, the ORDER BY clause is used to arrange the expression or column_name in ascending order or descending order. The programmer normally never used the ASC keyword for arrangement in ascending order.
If we want to arrange it in ascending or descending order then use the ASC or DESC keyword in the query like ORDER BY expression [ASC |DESC].
Let’s see the syntax of the MariaDB INSERT INTO SELECT statement with the ORDER BY clause by the following query:
SYNTAX:
INSERT INTO YOUR_TABLE_NAME(COLUMN_LIST)
SELECT COLUMN_NAME_1,COLUMN_NAME_2,COLUMN_NAME_3 FROM TABLE_NAME
WHERE [CONDITIONS]
ORDER BY COLUMN_NAME;
Now, let’s have a look at the INSERT INTO SELECT statement with the ORDER BY clause by the following query:
EXAMPLE:
CREATE TABLE MINI_USA_CUSTOMER(
ID INT,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30));
INSERT INTO MINI_USA_CUSTOMER(ID,FIRST_NAME,LAST_NAME)
SELECT ID,first_name,LAST_NAME
FROM customer_list
WHERE ID<=10
ORDER BY first_name;
SELECT * FROM MINI_USA_CUSTOMER;
The MariaDB CREATE TABLE statement is used to create another table called MINI_USA_CUSTOMER which will insert new records from the CUSTOMER_LIST table.
It carries the ID column with the INT data type, the FIRST_NAME column with VARCHAR(20) data type, and the LAST_NAME column with VARCHAR(30) data type in the MINI_USA_CUSTOMER table.
In the second query, we have used the INSERT INTO statement with the SELECT statement for inserting new records into the columns from the CUSTOMER_LIST table to the MINI_USA_CUSTOMER table.
In the WHERE condition, it will check to 10 with greater than or equal to the operator in the ID column. If the WHERE condition gets TRUE, it will then arrange the FIRST_NAME column in ascending order by using the ASC keyword in the ORDER BY clause.
If we want to check that we have retrieved all records from the MINI_USA_CUSTOMER table, then we will use the SELECT statement.

Read: MariaDB Queries – Detailed Guide
MariaDB Insert Into Select Primary Key
In this section, we will learn how to use the INSERT INTO SELECT statement with the PRIMARY KEY constraint in MariaDB.
In MariaDB, a primary key in MariaDB can be defined as one or more fields that help to uniquely define a record in a table. A primary key column can’t contain a null value and only one column can be a primary key in the table.
A primary key in MariaDB can be created by two methods: CREATE TABLE statement and ALTER statement.
First, let’s create another table called USA_CONSUMER which will insert records from the CUSTOMER_LIST table in the below query:
CREATE TABLE USA_CONSUMER(
ID INT );
In the preceding query, we have created a table called USA_CONSUMER which will insert records from the CUSTOMER_LIST of the ID column which data type INT and PRIMARY KEY constraint. It is done by using the CREATE TABLE statement to execute the query.
Now, we will use an example of the INSERT INTO SELECT statement for PRIMARY KEY constraint by the following query:
EXAMPLE:
INSERT INTO USA_CONSUMER(ID)
SELECT ID FROM CUSTOMER_LIST
WHERE ID<=50;
SELECT * FROM USA_CONSUMER;
In the first query, we have inserted records into the ID column of the USA_CONSUMER table from the CUSTOMER_LIST based by using the INSERT INTO SELECT statement. In the WHERE condition, the ID column will retrieve records till 50. If the WHERE condition gets TRUE, it will retrieve records in the result set.
If we want to retrieve all records from the USA_CONSUMER table then we will use the SELECT statement.

Read: MariaDB Primary Key With Examples
MariaDB Insert Into Select Year
Here, we will use the INSERT INTO SELECT statement with the YEAR function in the query and which is explained with the help of an illustrated example.
In MariaDB, the YEAR function is used to extract the year value from the expression or column_name in the query. Before we jump into a real example of the INSERT INTO SELECT statement with the YEAR function, we need to create another table for inserting new records into it.
Let’s see an illustrated example :
EXAMPLE:
CREATE TABLE USA_WALMART_COMPANY(
ID INT,
first_name VARCHAR(20),
LAST_NAME VARCHAR(30),
CUSTOMER_DATE year);
INSERT INTO USA_WALMART_COMPANY(ID,FIRST_NAME,LAST_NAME,CUSTOMER_DATE)
SELECT ID,FIRST_NAME,LAST_NAME,YEAR(CUSTOMER_DATE)
FROM WALMART_CUSTOMER;
SELECT * FROM USA_WALMART_COMPANY;
In the preceding query, we have created another table called USA_WALMART_COMPANY which will retrieve records from the WALMART_CUSTOMER table. And it is done by using the CREATE TABLE statement.
The second query requires us to insert new records for the ID, FIRST_NAME, and LAST_NAME columns, as well as determine the year value for the CUSTOMER_DATE column using the YEAR function and the INSERT INTO command.
It will select the records of all these columns and year values with the YEAR function from the WALMART_CUSTOMER table.
If we want to check and retrieve all records from the USA_WALMART_COMPANY table then we will use the SELECT statement.

You may also like to read the following MariaDB tutorials.
So, in this MariaDB tutorial, we have discussed how to use the MariaDB Insert Into Select statement and discussed several examples related to it. There are lists of the topic that comes under discussion:
- MariaDB Insert Into Select
- MariaDB Insert Into Select Auto_Increment
- MariaDB Insert Into Select on Duplicate Key Update
- MariaDB Insert Into Select Example
- MariaDB Insert Into Select Count
- MariaDB Insert Into Select Distinct
- MariaDB Insert into Select Group By
- MariaDB Insert Into Select Having
- MariaDB Insert Into Select JSON
- MariaDB Insert Into Select Multiple Columns
- MariaDB Insert Into Select Not Working
- MariaDB Insert Into Select Order By
- MariaDB Insert Into Select Primary Key
- MariaDB Insert Into Select Year
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.