2016-07-05 12 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で2つのテーブル間の重複を削除

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) ; 

です.... table2のではなく、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のステートメントを使用して2つの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

関連する問題