CREATE TABLE EMP1 (ID INT IDENTITY (1,1) ,SAL INT)
INSERT INTO EMP1 VALUES (2000)
INSERT INTO EMP1 VALUES (3000)
INSERT INTO EMP1 VALUES (4000)
INSERT INTO EMP1 VALUES (9000)
INSERT INTO EMP1 VALUES (1000)
----1.2nd Highest salary from emp table .
SELECT * FROM EMP1
select * from emp1 e1
where 1=(select count(distinct e2.sal) from emp1 e2 where e2.sal > e1.sal)
----2.Identifying the duplicate Records in a table .
select * from emp1
SELECT sal,
COUNT(sal) AS dupsal
FROM emp1
GROUP BY sal
HAVING ( COUNT(sal) > 1 )
INSERT INTO EMP1 VALUES (2000)
INSERT INTO EMP1 VALUES (3000)
INSERT INTO EMP1 VALUES (4000)
INSERT INTO EMP1 VALUES (9000)
INSERT INTO EMP1 VALUES (1000)
----1.2nd Highest salary from emp table .
SELECT * FROM EMP1
select * from emp1 e1
where 1=(select count(distinct e2.sal) from emp1 e2 where e2.sal > e1.sal)
----2.Identifying the duplicate Records in a table .
select * from emp1
SELECT sal,
COUNT(sal) AS dupsal
FROM emp1
GROUP BY sal
HAVING ( COUNT(sal) > 1 )
No comments:
Post a Comment