Friday, April 26, 2013

Delete duplicate records from a table

1 ) Write a Query To Delete The Repeted Rows from emp table;
SQL>Delete from emp where rowid not in(select min(rowid)from emp group
by ename)
               
2) TO DISPLAY 5 TO 7 ROWS FROM A TABLE
SQL>select ename from emp
         where rowid in(select rowid from emp where rownum<=7
         minus
  select rowid from empi where rownum<5)

3)  DISPLAY  TOP N ROWS FROM TABLE?

SQL>SELECT * FROM
                (SELECT *  FROM EMP ORDER BY ENAME DESC)
                 WHERE ROWNUM <10;

4) DISPLAY   TOP 3 SALARIES FROM EMP;
SQL>SELECT SAL FROM ( SELECT  * FROM EMP ORDER  BY SAL DESC )
                   WHERE ROWNUM <4

5) DISPLAY  9th FROM THE EMP TABLE?
SQL>SELECT ENAME FROM EMP
                WHERE ROWID=(SELECT ROWID FROM EMP WHERE ROWNUM<=10
                MINUS
                SELECT ROWID FROM EMP WHERE ROWNUM <10)
                select second max salary from emp;
                select max(sal) fromemp where sal<(select  max(sal) from emp);

No comments:

Post a Comment