'Truncating, Selecting data from multiple tables using joins and then inserting data into separate table in spring boot

I am using a spring boot application. I have multiple tables and using inner joins, I want to populate a temp table. Before populating, I have to truncate the table.

The below query works fine in SQL server management studio.

truncate table temp_table
insert into temp_table (col1, col2, col3, col4)
select T1.col1, T1.col2, T3.col3, T1.col4 
from ((Table3 as T3
inner join Table2 as T2 on T2.abc = T3.abc)
inner join Table1 as T1 on ((T1.col1 = T2.col1) and (T1.col2=T2.col2)))

I know there are various ways to do it, but what is the most efficient way to do it in spring boot, especially if tables contain 3-4 million records.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source