• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

OneToMany关系。如何删除行?

my database structureOneToMany关系。如何删除行?

你好。我刚刚学会了如何选择所有相关的数据,比方说,行 tennismatch.ID = 1:

SELECT * FROM tennismatch m 
JOIN tennismatch_tennisset ms 
ON m.`ID` = ms.`TennisMatch_ID` 
JOIN tennisset s 
ON ms.`mapOfSets_ID` = s.`ID` 
JOIN tennisset_game sg 
ON s.`ID` = sg.`TennisSet_ID` 
JOIN game g 
ON sg.`gamesMap_ID` = g.`ID` 
JOIN game_point gp 
ON g.`ID` =gp.`Game_ID` 
JOIN point p 
ON gp.`points_ID` = p.`ID` 
WHERE m.`ID` = 1 

,但我想不出如何删除这一切。 非常感谢提前。

===========解决方案如下:

使用DELETE JOIN语句

<code class="prettyprint-override">DELETE m, s, g, p, ms, sg, gp 
FROM tennismatch m 
JOIN tennismatch_tennisset ms ON m.ID = ms.TennisMatch_ID 
JOIN tennisset s ON ms.mapOfSets_ID = s.ID 
JOIN tennisset_game sg ON s.ID = sg.TennisSet_ID 
JOIN game g ON sg.gamesMap_ID = g.ID 
JOIN game_point gp ON g.ID = gp.Game_ID 
JOIN point p ON gp.points_ID = p.ID 
WHERE m.ID = 1 
</code>

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)