Urgent Urgent [message #82275] |
Wed, 14 May 2003 23:06 |
Sam
Messages: 255 Registered: April 2000
|
Senior Member |
|
|
Please can anybody help me out
suppose there is column "deptno"and i want to delete only those rows which has deptno=90,
so can anybody giv me the syntax of how to delete rows for a particular column.
sam
|
|
|
Re: Urgent Urgent [message #82279 is a reply to message #82275] |
Thu, 15 May 2003 00:59 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
SQL forum.
Basically it is:DELETE FROM dept d
WHERE rowid <> ( SELECT MIN(rowid)
FROM dept
WHERE deptno = d.deptno ) This statement will delete all records but one for all deptno values. The principle is: we need to uniquely identify each record (even though they're duplicates). For that, we can use ROWID. So if we say that we want to delete all duplicates which have a different rowid than the one with the smallest rowid, the latter won't be deleted. In our example, duplicates are identified by the deptno column so we evaluate that in the inner select. If there are more criteria, e.g. dname, we need to add "AND dname = d.dname" to the inner select.
MHE
|
|
|