adspace
Answer Posted / Jitendra Singh Yadav
In SQL Server, you can use the DELETE statement with JOIN to delete orphan records. Here's an example using self-join:
```sql
DELETE A
FROM TableA AS A
JOIN (
SELECT ParentID, MAX(ID) as MaxID
FROM TableA
GROUP BY ParentID
) AS B ON A.ParentID = B.ParentID AND A.ID < B.MaxID
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is normalization and what are the advantages of it?
How to enter binary string literals in ms sql server?
What is temporary table in sql server? Why we use temp table?
How raid can influence database performance?
Can you index views?
How do I find the sql server version?
What are the source of constraints?
what is spatial nonclustered index
Does view occupy space?
Is it possible to have clustered index on separate drive from original table location?
What is a scheduled job or what is a scheduled task?
What is sql or structured query language?
What is the difference between upgrade and migration in sql server?
what is the difference between openrowset and openquery?
Why use identity in sql server?