xikoseb:
私は、2つのテーブルを持っているtable_a
、とtable_b
。私はからすべての行を削除する必要がtable_a
私の作品以下、(および声明まで)で、:(ETIDがで、整数ですtable_a
)
delete m1
from table_a m1
inner join table_a m2 on m1.etid = m2.etid and m1.id <> m2.id
where m1.gid = 198 and (here i need to make sure that each row with etid that fulfills above criteria and will be deleted, is also of type 'product', info which is stored in table_b)
table_b
2つの列があります。 nid
と、type
カラムの異なる値がtype
2つである:'product'
及び'raw'
nid
列に格納されているINT番号であるetid
のtable_a
。
私は、別の参加を追加しなければならないと思うし、また声明では、ように...どのように上記のスニペットが変更されなければならないだけで、適切な行を選択しますか?私は、実行時間の速度の点で、また、これを行うには、最もパフォーマンスの高い方法を見つけるしたいと思います
https://dbfiddle.uk/?rdbms=mysql_5.6&fiddle=c16369b42847fbfb9a609e613945fc01
上記のサンプルデータ。
予想される出力:
+----+------+---------+-----+
| id | etid | title | gid |
+----+------+---------+-----+
| 1 | 120 | Title1 | 198 | <-row that must be deleted
| 2 | 121 | Title2 | 55 |
| 3 | 120 | Title1 | 674 |
+----+------+---------+-----+
最終的な出力:
+-----+------+---------+-----+
| id | etid | title | gid |
+-----+------+---------+-----+
| 2 | 121 | Title2 | 55 |
| 3 | 120 | Title1 | 674 |
+-----+------+---------+-----+
離れて渡します:
あなたは別のに参加する必要がありますtable_b
:
delete m1
from table_a m1
inner join table_a m2 on m1.etid = m2.etid and m1.id <> m2.id
inner join table_b b on b.nid = m1.etid
where m1.gid = 198 and b.type = 'product'