| Author |
Topic |
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-08-25 : 06:00:51
|
| hi iam having a table like xwhere record are like thisa b c100.81 1567 1553100.81 1772 1772100.81 1772 1831100.81 1782 1774there are so many records in it like this iam giving an examplei want a query where i can delete a record if a and b are repeating twice then we have to consider the maximun one of c.that means out of this100.81 1772 1772100.81 1772 1831i want only 2 row to be there.please give a delete query for this. |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-08-25 : 06:03:12
|
| select a,b, max(c) c into #tmpa from x group by a,btruncate table xinsert into xselect a,b,c from #tmpadrop table #tmpa |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-25 : 06:11:27
|
| delete x from tablename x left join (select a,b,max(c) as c from tablename group by a,b)s on s.a = x.a and s.b = x.b and s.c = x.c where s.c is null |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-08-25 : 06:12:18
|
| but there are some other values also other than this.those how can i proceed for examplea b c100.81 1638 1617100.81 1772 1831100.81 1649 1657100.81 1622 1598100.81 1567 1553100.81 1772 1772100.81 1715 1771100.81 1527 1513100.81 1782 1774 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-25 : 06:21:58
|
| So, you want only one value of b anc c for each a?MadhivananFailing to plan is Planning to fail |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2009-08-25 : 06:26:15
|
quote: Originally posted by rajasekhar857 but there are some other values also other than this.those how can i proceed for examplea b c100.81 1638 1617100.81 1772 1831100.81 1649 1657100.81 1622 1598100.81 1567 1553100.81 1772 1772100.81 1715 1771100.81 1527 1513100.81 1782 1774
have you tried running the select part of my query? |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-08-25 : 06:27:54
|
| no 100.81 1772 1831 100.81 1772 1772 are there out of i want 100.81 1772 1831 because c is maxrest of columns should be there that is i required.only 100.81 1772 1772 got deleted |
 |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2009-08-25 : 06:49:55
|
| [code]DELETE DFROM( SELECT * ,ROW_NUMBER() OVER (PARTITION BY a, b ORDER BY c DESC) AS RowNum FROM YourTable) DWHERE RowNum > 1[/code] |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-08-25 : 06:51:03
|
| actually my table is having 17 columns out of that i have shown 3 columns where i need to delete as above mentioned ones.because a and b columns shoud not be repeated that is the case.so if got repeated i have to consider max value of c and min value shoud be deleted. |
 |
|
|
rajasekhar857
Constraint Violating Yak Guru
396 Posts |
Posted - 2009-08-25 : 06:54:06
|
| DELETE DFROM( SELECT * ,ROW_NUMBER() OVER (PARTITION BY a, b ORDER BY c DESC) AS RowNum FROM YourTable) DWHERE RowNum > 1HOW CAN I DO THIS IN ORACLE |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-25 : 08:22:55
|
quote: Originally posted by rajasekhar857 DELETE DFROM( SELECT * ,ROW_NUMBER() OVER (PARTITION BY a, b ORDER BY c DESC) AS RowNum FROM YourTable) DWHERE RowNum > 1HOW CAN I DO THIS IN ORACLE
POST in Oracle forums such as www.orafaq.comMadhivananFailing to plan is Planning to fail |
 |
|
|
|