Answer by K0D4 for SQL: Remove rows whose associations are broken (orphaned...
I've found in SQL 2008 R2, if your "in" clause contains a null value (perhaps from a table who has a reference to this key that is nullable), no records will be returned! To correct, just add a clause...
View ArticleAnswer by Farjad for SQL: Remove rows whose associations are broken (orphaned...
For future reference. For these kind of long operations. It is possible to optimise the server independently of the SQL. For example detach the sql service, defrag the system disk, if you can ensure...
View ArticleAnswer by Denis de Bernardy for SQL: Remove rows whose associations are...
use two anti joins and or them together:delete from your_tablewhere user_id not in (select id from users_table)or item_id not in (select id from items_table)once that's done, consider adding two...
View ArticleAnswer by user753676 for SQL: Remove rows whose associations are broken...
think there is no faster solution when there are so many rowsthat are on your server 157 rows per secondcheck user id if mysql num rows = 0 than delete the downloads and also check the item_idthere was...
View ArticleAnswer by Adrian Serafin for SQL: Remove rows whose associations are broken...
delete from your_table where user_id not in (select id from users_table) or item_id not in (select id from items_table)
View ArticleSQL: Remove rows whose associations are broken (orphaned data)
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...
View Article