-1

我有多个表 list_of_students、sport_students。

在 sport_students 我有一个名为

list_of_house_id 和 list_of_students 我有字段 list_of_class_id 和 list_of_house_id。

现在,但我需要删除从 sport_student acc 到 house_id 和 list_of_class_id 的记录。

我已经尝试过这个查询,但似乎不起作用

DELETE FROM `sport_students` JOIN list_of_students as student on `sport_student.list_house_id`= `student.list_of_house_id` WHERE `sport_student.list_of_house_id`=1 and `list_of_students.list_of_class_id`=1

有人知道怎么做吗?

4

2 回答 2

0

试试这个:

DELETE sp
  FROM `sport_students` sp
  JOIN list_of_students as student 
    ON sp.list_house_id = student.list_of_house_id
 WHERE sp.list_of_house_id=1 
   AND student.list_of_class_id=1;

有关更多信息,请参阅MySQL:删除语法

于 2012-12-17T06:41:48.660 回答
0
DELETE  FROM sport_students
WHERE   list_of_house_id IN (
            SELECT  list_of_house_id
            FROM    list_of_students
            WHERE   list_of_class_id = 1 AND list_of_house_id =1 
        )
于 2012-12-17T07:05:34.647 回答