[英]mysql DELETE with field check from another table
Good morning all, happy thursday morning. 大家早上好,周四早上很开心。 I wish I could have done this by myself but since I'm not a master in MySQL statements (yet) and I got lost in this
DELETE
query, here it goes... 我希望自己可以做到这一点但是因为我不是MySQL语句中的主人(但是)我在这个
DELETE
查询中迷失了,这里有...
I have to do a simple DELETE
query like this, (deleting a comment by its id) 我必须这样做一个简单的
DELETE
查询,(通过其id删除注释)
DELETE FROM mya_news_comments WHERE comment_id='".$_GET['comment_id']."'";
but at the same time, to prevent people deleting comments throughout the website i need to ensure that the person deleting this comment is who it is supposed to be (in our case, an artist). 但与此同时,为了防止人们在整个网站上删除评论,我需要确保删除此评论的人是应该是谁(在我们的例子中是艺术家)。
I have another table mya_news
which has among the fields news_id
, artist_id
In mya_news_comments
I also have a field called news_id
我有另一个表
mya_news
,其中包含字段news_id
, artist_id
在mya_news_comments
我还有一个名为news_id
的字段
So I need to check that I delete the comment_id of the particular artist, not of other artist. 所以我需要检查是否删除了特定艺术家的comment_id,而不是其他艺术家。 Basically i need to cross-check if the
news_id
field from mya_news_comments
checks out with a field with same news_id
from mya_news
, and artist_id
from mya_news
is equal to $_id
(which holds my artist_id
) 基本上我需要交叉检查
news_id
从外地mya_news_comments
检查出与同场news_id
从mya_news
,并artist_id
从mya_news
等于$_id
(持有我artist_id
)
I'm really stuck here. 我真的被困在这里了。 I'd be glad to give more details if needed.
如果需要,我很乐意提供更多细节。
Thanks. 谢谢。
DELETE mya_news_comments
FROM mya_news_comments
WHERE mya_news_comments.comment_id = (SELECT [another_table].comment_id WHERE [cond])
AND mya_news.artist_id = (SELECT [another_table].artist_id WHERE [cond]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.