netstat -ab
shows which process runs on which port. If you need to find a process which runs on a particular port, the command can be used as follows
netstat -ab | find ":8080 "
This blog mainly contains technical stuff. It may contain info of some events too.
Saturday, August 14, 2010
Tuesday, August 10, 2010
How to Remove Duplicate Records from a Table, Considering a Subset of Columns - Sql
I wanted to delete some duplicate records from a table. "Duplicate" doesn't mean identical records in this scenario. I wanted to check whether the values in a subset of columns are identical and if so, to remove additional records keeping just one record in the table.
Let's assume we have a table called Person like below
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
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
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 |
Subscribe to:
Posts (Atom)