Answer the question
In order to leave comments, you need to log in
Sql DELETE with nested SELECT?
Good afternoon.
There are tables
Semesters(Id,Name,CreatedBy)
Groups(Id,Name,SemesterId) //SemesterId is bound to Semesters.Id
We need to delete data from the Groups table, let's say the user sends - delete group 1, then we need to check (via join) whether he is the creator of the "Semester" in which this group is located and if yes, then delete it.
Why exactly? It’s just that if a “too smart dude” comes across, so that he doesn’t send the IDs of those groups that do not belong to him for deletion
Answer the question
In order to leave comments, you need to log in
delete from groups WHERE SemesterId IN (SELECT id FROM semesters WHERE userid=7) AND groups.id=4
Check for user 7 who wants to delete group 4
delete G from Groups
inner join Semesters S on G.SemesterId=S.id
where exists
(// check that he is the creator)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question