mysql - delete broken records (records not having foreign key id corresponding records)

other
voted: 1
vote
mysql delete nested subquery

To delete broken records nested subquery must be used, because mysql does not have ability to delete from subquery on the same table.

delete from employee where employee.id in(
    select * from(
        select employee.id from employee left outer join company on (company.id = employee.company_id)
        where company.id is null
        order by employee.id desc
    ) as 2id
)
working url: not entered
version: not entered
Leave a Comment:
Characters left:
No comments yet.