回答編集履歴
1
調整
test
CHANGED
@@ -1 +1,17 @@
|
|
1
1
|
新テーブルのname、colorに複合ユニーク属性をつけて、insert ignore intoすればよいでしょう
|
2
|
+
|
3
|
+
# 参考
|
4
|
+
```SQL
|
5
|
+
create table tbl_a (id int primary key,name varchar(10),color varchar(10),quantity int);
|
6
|
+
insert into tbl_a values
|
7
|
+
(1,'apple','red',5),
|
8
|
+
(2,'apple','green',3),
|
9
|
+
(3,'apple','red',2),
|
10
|
+
(4,'apple','yellow',1),
|
11
|
+
(5,'banana','yellow',3),
|
12
|
+
(6,'banana','green',1),
|
13
|
+
(7,'banana','green',2),
|
14
|
+
(8,'banana','green',3);
|
15
|
+
;
|
16
|
+
select * from tbl_a as t1 where not exists(select 1 from tbl_a where name=t1.name and color=t1.color and id<t1.id);
|
17
|
+
```
|