我有一个从表中删除重复记录的场景,但我不明白如何做到这一点,因为大数据和与三个表的关系。
candidates_table是包含重复记录的候选表。和字段是
candidate Table :
candidate_id |f_name |l_name| skills
1 Ab c php,MySQL
2 Ab c php,MySQL,java script
3 cd g Java,hibernate,spring
4 cd g Java,hibernate
5 ef h XML,Web service
6 ef h XML,Web service,json
Attachment Table:
attachment_id |candidate_id
1 2
2 4
3 8
4 9
5 10
Canidate_job_order Table:
joborder_id |candidate_id
1 2
2 4
3 8
4 9
5 10 attachments_table是一个表,如果任何候选人有附件,那么candidate_id就会出现在这里。
如果他是针对任何工单提交的,则candidate_joborder_table包含candidate_id。
我必须删除候选人表中的重复候选人谁没有附件,没有提交针对任何工作order.Also我必须放1,如果一切都匹配相同。我想从候选表中删除除canidate_id 2,4,6以外的所有记录。
发布于 2016-05-16 22:19:18
删除所有没有附件且未提交职务订单的候选人。
DELETE * FROM candidate WHERE candidate_id NOT IN (
SELECT C.candidate_id FROM candidate C
INNER JOIN Attachment A ON A.attachment_id = C.candidate_id
INNER JOIN Canidate_job_order CJO ON CJO.candidate_id = C.C.candidate_id
)如果某些候选人只有附件,如果您引用了带有外键的表,则此删除操作可能不起作用!
发布于 2016-05-16 23:01:47
试试这个:
delete from candidate c where candidate_id not in (select max(candidate_id)
from candidate
group by f_name ,l_name, skills)
and not exists (select 1 from Attachment A where A.attachment_id = C.candidate_id)
and not exists (select 1 from Canidate_job_order CJO where CJO.candidate_id = C.C.candidate_id) and not in ( 2,4,6);https://stackoverflow.com/questions/37255100
复制相似问题