Q: Duplicate Row inserted in individual table while insert using multiple table left join I want to insert in 5 different tables each having relation with one parent table. But while inserting there is duplication issue in each table. My SQL script is below:
INSERT INTO temp_data_table(
    main_id,
    class,
    CODE,
    NAME,
    age,
    address,
    sub1,
    sub2,
    number,
    databse,
    risk,
    STATUS
)
SELECT DISTINCT 
    MT.id AS main_id,
    MT.class AS class,      
    t1.code AS CODE,
    t1.name AS NAME,
    t2.age AS age,
    t2.address AS address,
    t3.sub1 AS sub1,
    t3.sub2 AS sub2,
    t4.no AS number,
    t4.databse AS databse,
    t5.risk AS risk,
    t5.status AS STATUS
FROM my_dataBase.mainTable MT 
    LEFT JOIN my_dataBase.table1 t1 ON t1.mt_id=MT.id
    LEFT JOIN my_dataBase.table2 t2 ON t2.mt_id=MT.id
    LEFT JOIN my_dataBase.table3 t3 ON t3.mt_id=MT.id
    LEFT JOIN my_dataBase.table4 t4 ON t4.mt_id=MT.id
    LEFT JOIN my_dataBase.table5 t5 ON t5.mt_id=MT.id;

Note that mt_id Is autoincrement_id for mainTable.
While inserting into temp_data_table I found that 8 records of table2, but in table2 there is only 2 records of matching criteria.

A: If you wants to insert all tables have relation data then use INNER JOIN
In left join it always return minimum no of records=main table records count
INSERT INTO temp_data_table(
main_id,
class,
CODE,
NAME,
age,
address,
sub1,
sub2,
number,
databse,
risk,
STATUS
)
SELECT DISTINCT 
MT.id AS main_id,
MT.class AS class ,      
t1.code AS CODE,
t1.name AS NAME,
t2.age AS age,
t2.address AS address,
t3.sub1 AS sub1,
t3.sub2 AS sub2,
t4.no AS number,
t4.databse AS databse,
t5.risk AS risk,
t5.status AS STATUS
FROM my_dataBase.mainTable MT 
INNER JOIN my_dataBase.table1 t1 ON t1.mt_id=MT.id
INNER JOIN my_dataBase.table2 t2 ON t2.mt_id=MT.id
INNER JOIN my_dataBase.table3 t3 ON t3.mt_id=MT.id
INNER JOIN my_dataBase.table4 t4 ON t4.mt_id=MT.id
INNER JOIN my_dataBase.table5 t5 ON t5.mt_id=MT.id;

