2016-07-05 2 views
0
table1 

    id  mcs  name  search_id 
    1  14  name1 70 
    2  14  name2 70 
    3  14  name3 70 

table2 

    id mcs  name  search_id 
    1 14  name1 70 
    2 14  name2 70 
    3 14  name4 70 
    4 14  name5 70 
    5 14  name6 70 

내가 원하는 나의 시련이MySQL의에서 두 테이블 사이의 중복을 제거

create temporary table find_duplicates SELECT * FROM table2 T1 WHERE 
      T1.mcs = T2.mcs AND T1.search_id = T2.search_id AND T1.name IN (SELECT T2.name FROM table2 T2) ; 

입니다 .... 표 2와하지 ANS는 SEARCH_ID 같은 MCS를 가지고 표 1에서에서 행을 선택하는 것입니다 그러나 그것은 나를 준다 열이 모호 나는 그것이 나에게주는이

 create temporary table find_duplicates SELECT)mcs,name,search_id) FROM table2 T1 WHERE 
      T1.mcs = T2.mcs AND T1.search_id = T2.search_id AND T1.name IN (SELECT T2.name FROM table2 T2) ; 

을 시도하는 경우에도 ... 을 ID라는 이름의 열을 복제

어떤 도움 ???

+2

의 사용 가능한 복제 [MySQL의 문을 사용하여 두 개의 MySQL의 테이블 사이의 차이를 찾는 방법?] (http://stackoverflow.com/questions/18964709/how-to-find-difference-between-two -mysql-tables-using-mysql-statement) – splash58

+0

내 질문을 잘 읽으십시오. –

답변

0
/* 
create table table1 (id int, mcs int , name varchar(10),  search_id int); 
insert into table1 values 
( 1,  14,  'name1', 70), 
( 2,  14,  'name2', 70), 
( 3,  14,  'name3', 70); 

create table table2 (id int, mcs int , name varchar(10),  search_id int); 
insert into table2 values 
( 1, 14,  'name1' , 70), 
( 2, 14,  'name2' , 70), 
( 3, 14,  'name4' , 70), 
( 4, 14,  'name5' , 70), 
( 5, 14,  'name6' , 70); 
*/ 

create temporary table find_duplicates 
select t2.* 
from table2 t2 
left outer join  table1 t1 on t1.mcs = t2.mcs and t1.name = t2.name and t1.search_id = t2.search_id 
where t1.id is null; 
0
create temporary table find_duplicates 
select distinct(t2.id) from table2 t2,table1 t1 where t1.mcs = t2.mcs 
and t1.search_id = t2.search_id and not find_in_set 
(t2.name,(select group_concat(name) from table1)) 
+0

몇 가지 설명을 추가하면 좋을 것입니다! :) – gofr1

+0

@ gofr1 질문 배터를 먹는다. 나는 그 사용자가이 결과를 원한다고 생각하고이 쿼리를 만들었다. 그것은 옳은가 틀린가? –

+0

죄송합니다. 확인할 수 없습니다. 귀하의 대답은 설명이 없기 때문에 추측 할 수있는 저질로 표시되었으며이 문제에 대한 의견을 추가합니다. 추가 할 항목이 없다면 OK를 클릭하십시오. :) – gofr1

관련 문제