[英]php join 3 tables then insert to 4th
Here is the JOIN: 这是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()中字段的名称和顺序与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. 附带说明一下,请考虑尽可能在表之间为g_dist之类的字段命名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.