-2

我正在运行查询以从表中删除。

delete from sps
inner join str on str.studentid = sps.studentid 
where str.studentid like '%2012%psy%' 
  and str.semesterid=2 
inner join papers on papers.id = sps.paperid 
where papers.c_id=10 
  and papers.p_semid=2

我不知道为什么它没有显示任何结果并给我一个错误。

错误是:

#1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 2 行的 'inner join str on str.studentid=sps.studentid where str.studentid like '%2012%ps' 附近使用

4

2 回答 2

1

将两个WHERE子句的两个谓词在查询末尾移动到一个WHERE子句中,如MysqlDELETE语法所述。就像是:

DELETE s 
FROM sps s
INNER JOIN str ON str.studentid = s.studentid 
INNER JOIN papers ON papers.id = s.paperid 
WHERE str.studentid LIKE '%2012%psy%' 
  AND str.semesterid = 2 
  AND papers.c_id = 10 
  AND papers.p_semid = 2
于 2012-09-08T09:06:42.613 回答
0

您可以WHERE在单个查询中使用一次子句。
试试这个查询

DELETE sps FROM sps
INNER JOIN str ON str.studentid=sps.studentid
INNER JOIN papers ON papers.id=sps.paperid 
WHERE papers.c_id=10 AND papers.p_semid=2
AND str.studentid LIKE '%2012%psy%' AND str.semesterid=2 

或者

DELETE FROM sps, str, papers 
USING sps 
      INNER JOIN str ON str.studentid=sps.studentid
      INNER JOIN papers ON papers.id=sps.paperid 
WHERE   papers.c_id=10 
    AND papers.p_semid=2
    AND str.studentid LIKE '%2012%psy%' 
    AND str.semesterid=2 
于 2012-09-08T09:13:13.087 回答