programing

SQL SELECT 문이 DELETE에 대해 작동하지 않습니다.

mailnote 2023. 8. 29. 20:47
반응형

SQL SELECT 문이 DELETE에 대해 작동하지 않습니다.

user_id 및 사용자 이름과 관련된 응답을 삭제하기 위해 실행하려는 SQL 문이 있습니다.쿼리는 선택을 시도할 때 작동하지만 삭제에는 작동하지 않습니다.DELETE 문에서 발생하는 오류는 다음과 같습니다.

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AS ans INNER JOIN users AS usr ON ans.user_id = usr.user_id WHERE (usr.userna...' at line 1
Query is: DELETE FROM answers AS ans INNER JOIN users AS usr ON ans.user_id = usr.user_id WHERE (usr.username = 'antonios')

SELECT 문에서 얻은 출력:

1   answer text goes here   1   1   a   12  44  44  antonios    U4HhMNnasQB1919QduzHO9+tgWoxsfqMY4MDUwYDDqQ=    $argon2id$v=19$m=125000,t=4,p=1$gE6rtZdzpBaehzlyrVreRQ$WuhSeAaXE2bX3N4/k1yu3yQm9p7UdKGeCU/vmYn+M7c  0   0   0   0   0   2020-10-14

SELECT 문:

SELECT * FROM answers AS ans INNER JOIN users AS usr ON ans.user_id = usr.user_id WHERE (usr.username = 'username');

DELETE 문:

DELETE FROM answers AS ans INNER JOIN users AS usr ON ans.user_id = usr.user_id WHERE (usr.username = 'username');

테이블 구조users:

user_id             int(11) NO                      PRIMARY_KEY               auto_increment
username            varchar(40)         NOT_NULL    MUL_KEY     
email               varchar(128)        NOT_NULL            
password            char(98)            NOT_NULL            
userScore           int(10) unsigned    NOT_NULL                  DEFAULT: 0    
questionsAnswered   int(10) unsigned    NOT_NULL                  DEFAULT: 0    
highestAnswerStreak int(10) unsigned    NOT_NULL                  DEFAULT: 0    
correctAnswers      int(10) unsigned    NOT_NULL                  DEFAULT: 0    
wrongAnswers        int(10) unsigned    NOT_NULL                  DEFAULT: 0    
activeSince date    NOT_NULL            

테이블 구조answers:

answers_id      int(11)     NOT_NULL   PRIMARY_KEY   auto_increment
answerText      text        NOT_NULL            
question_id     int(11)     NOT_NULL            
isCorrect       tinyint(4)  NOT_NULL            
choiceLetter    varchar(1)  NOT_NULL            
questionNumber  smallint(6) NOT_NULL            
user_id int(11) NOT_NULL            

DELETE 문에 대한 예상 출력은 다음의 하나 이상의 행에 영향을 줍니다.answers테이블(WHERE 절의 사용자 이름에서 가져온 user_id에 할당된 모든 행)을 삭제합니다.

가깝습니다.삭제할 테이블을 나열해야 합니다.예를 들어:

DELETE ans
    FROM answers ans INNER JOIN
         users usr
         ON ans.user_id = usr.user_id
    WHERE usr.username = 'username';

언급URL : https://stackoverflow.com/questions/64375852/sql-select-statement-doesnt-work-for-delete

반응형