开发者

Sql Query to insert data based on id

开发者 https://www.devze.com 2023-02-12 05:46 出处:网络
I currently have 4 tables, Guardian -Name -RankingG Times开发者_运维问答 -Name -RankingT Identity -idName

I currently have 4 tables,

Guardian

-Name

-RankingG

Times开发者_运维问答

-Name

-RankingT

Identity

-idName

-Name

Ranking

-idName

-RankingT

-RankingG

Times and Guardian do have some different names. I have currently inserted the Names from Times and Guardian into Identity with an autoincrement idName. Now how do I insert the RankingT into Ranking from Times with the corresponding idName from Identity and do the same with RankingG from Guardian


Note: This will not work if there are duplicate Name's:

INSERT Ranking (idName, RankingT)
SELECT i.idName, t.RankingT, g.RankingG
FROM `Identity` i 
    LEFT JOIN Times t USING(Name)
    LEFT JOIN Guardian g USING(Name)
0

精彩评论

暂无评论...
验证码 换一张
取 消