2014-10-25 3 views
0

두 개의 열이있는 표가 있습니다 : applicationidstudentid입니다. applicationidapplicationid이 이전 값이고, studentid이 (applicationid이 이미 새 값과 동일한) studentid과 같지 않은 새 값으로 업데이트하려고합니다. 표는 다음과 같습니다, 그리고 나는 2222222222222 applicationid 1111111111111로 업데이트 할, 그러나 항상 :MySQL 업데이트 및 삭제 수수께끼

--applicationid-- --studentid-- 
--1111111111111-- --111111111-- // RIGHT HERE! 
--1111111111111-- --555555555-- 
--2222222222222-- --666666666-- // Here I want to simply update application id to 1111111111111 
--2222222222222-- --111111111-- // I WANT TO DELETE THIS ROW, BECAUSE THE UPDATE RESULT ALREADY EXISTS! ^^ 
--2222222222222-- --777777777-- // I also want this row to be updated. 

이 내가있어 질의이지만, 심지어을 경우, 새로운 값으로 갱신 applicationid을한다 이미 존재하는 결과 :

UPDATE students_applications 
SET applicationid = 1111111111111 
WHERE applicationid = 2222222222222 

의견이 있으십니까?

미리 감사드립니다.

+0

어떤 데이터베이스를 사용하고 있습니까? –

+0

나는 mysql을 사용하고있다 – RoyTek

답변

0

이와 비슷한?

delete from table where studentid = '111111111' and applicationid <> '111111111111111'; 
update table set applicationid = '11111111111111'; 
+0

고마워,하지만 안돼. 내가 가지고있는 유일한 데이터는 수정하고 싶은 두 개의 applicationID이지만, 충분하다. 나는 studentid와 새로운 applicationid의 조합이 아직 종료되지 않는 행에서 applicationid를 업데이트하고 해당 studentid와 새로운 applicationid의 조합이 존재하는 행을 삭제하려고합니다. – RoyTek