Let's assume we have a table called Person like below
Id | Name | Age | City |
10 | Sunil | 24 | Matara |
11 | Sandun | 25 | Colombo |
12 | Nimali | 23 | Matara |
13 | Dilani | 25 | Matara |
14 | Savini | 25 | Galle |
Say we need only one person from one city. Then we have to remove two records having Matara as the city.
To do that we can write a query like below
DELETE FROM Person WHERE Id > (SELECT MIN(Id) FROM Person p where p.City = Person.City)
We used Id as a controller to decide which records to delete and to keep just one record (by checking min Id).
After executing the query, the table will look like this
Id | Name | Age | City |
10 | Sunil | 24 | Matara |
11 | Sandun | 25 | Colombo |
14 | Savini | 25 | Galle |
4 comments:
We can learn here how o remove duplicate record from a table and we can see the writer discussed it very nicely and clearly anyway we can see this post is helping us very much in superiorpapers.com review that really deserve thanks and appreciation.
We must should read this post to know easily about how to remove duplicate record from a table. I will share this information with trust essay writing service also to make a very beneficent flow of knowledge easily.
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.
Student writers who have no experience in writing may waste much time on creating a sound title first. However, it is much better to start working on the essay first and produce a good and corresponding title later thoroughly tested to ensure the work you receive is original https://advanced-writer.com/essay-title.
Post a Comment