Quantcast
Channel: SQL: Remove rows whose associations are broken (orphaned data) - Stack Overflow
Viewing all articles
Browse latest Browse all 6

SQL: Remove rows whose associations are broken (orphaned data)

$
0
0

I have a table called "downloads" with two foreign key columns -- "user_id" and "item_id". I need to select all rows from that table and remove the rows where the User or the Item in question no longer exists. (Look up the User and if it's not found, delete the row in "downloads", then look up the Item and if it's not found, delete the row in "downloads").

It's 3.4 million rows, so all my scripted solutions have been taking 6+ hours. I'm hoping there's a faster, SQL-only way to do this?


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images