php加入3个表然后插入到第4个

Here is the JOIN:

SELECT 
    gc3025_raid_results.raid_id, 
    gc3025_game_units.planet_id, 
    gc3025_game_units.g_dist, 
    gc3025_game_units.unit_name, 
    gc3025_units_base.unit_type, 
    gc3025_game_units.code, 
    gc3025_game_units.cdamage, 
    gc3025_units_base.defense_raid_score, 
    gc3025_units_base.raid_damage 
FROM gc3025_game_units 
    JOIN gc3025_units_base 
        ON gc3025_game_units.code = gc3025_units_base.unit_code 
    JOIN gc3025_raid_results 
        ON gc3025_raid_results.district_idg = gc3025_game_units.g_dist

I then need to insert into another table

INSERT INTO gc3025_raid_defenders( 
    raid_ids, planet_id, district_id, 
    unit_name, unit_type, unit_code, 
    raid_score, raid_damage)
    SELECT ... (see above) ...

Any suggestions would be appreciated.

This should get you going, but you will need to add the other fields. Make sure the name and order of the fields in the insert() match the fields in the select()

insert into gc3025_raid_defenders (raid_ids, planet_id, etc...)
select (gc3025_raid_results.raid_id, gc3025_game_units.planet_id, etc...)
from gc3025_game_units gu
join gc3025_units_base ub
    on gu.code = ub.unit_code
join gc3025_raid_results rr
    on gu.g_dist = rr. district_idg

On a side note, think about naming your fields like g_dist consistently between tables, if possible.