开发者

Sql Query to insert data based on id

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜