Elegant way to remove orphan rows?

后端 未结 5 2134
小蘑菇
小蘑菇 2021-02-19 02:51

I have a table with a lot of history entries that contain customer IDs.

There is a separate customer table. Occasionally some of the customer entries are removed.

<
5条回答
  •  忘掉有多难
    2021-02-19 03:26

    delete from history_table where customer_id not in (select customer_id from customers)
    

    did you mean something like this?

提交回复
热议问题