Hcl Technologies 3+ Experienced Sql server Questions

Answer Posted / babi

--1)select all the Employees who does not have phone?

SELECT * FROM EMPLOY WHERE EMPID NOT IN(SELECT EMPID FROM PHONE)


--2)Dispaly all managers from table(Manager id is same as Empid)

SELECT * FROM EMPLOY E WHERE E.EMPID=E.MGRID


--3)How to know How many tables contain Empno as a column in database?

SELECT name FROM sys.objects WHERE OBJECT_ID IN (SELECT object_id FROM sys.columns WHERE NAME like 'EMPNO')

--4)Find duplicate rows in a table or
-- if we have table with one column which has many records which are not distinct. How to find out the distinct values from that column and number of times its repeated


SELECT * FROM (
SELECT *,ROW_NUMBER()OVER(PARTITION BY EMPNAME ORDER BY EMPID ) AS NUMS FROM EMPLOY ) A WHERE NUMS>1

CREATE TABLE ONE(ID INT)
INSERT INTO ONE VALUES('1'),('2'),('3'),('4'),('5'),('1'),('2'),('3'),('4'),('5'),('1'),('2'),('3'),('4'),('5')
SELECT ID,COUNT(*) FROM ONE group by ID having COUNT(*)>1



--5) How to delete the rows which are duplicate?(Don't remove both duplicate records.)


WITH TA
AS
(
SELECT EMPID,EMPNAME,ROW_NUMBER() OVER(PARTITION BY EMPNAME ORDER BY SAL DESC ) AS Nums
FROM EMPLOY
)
DELETE FROM TA WHERE Nums>1

WITH AT
AS
(
SELECT *,ROW_NUMBER() OVER(PARTITION BY PHONENUMBER ORDER BY EMPID DESC)AS PHONENUMS FROM PHONE
)
DELETE FROM AT WHERE PHONENUMS>1

--6)how to Find 6th highest sal ?


SELECT MIN(SAL) FROM EMPLOY WHERE SAL IN(
SELECT DISTINCT TOP(6) SAL FROM EMPLOY ORDER BY SAL DESC
)
SELECT TOP 1 SAL FROM (SELECT DISTINCT TOP 6 SAL FROM EMPLOY ORDER BY SAL DESC) EMPLOY ORDER BY SAL

SELECT * FROM
( SELECT DISTINCT TOP 6 SAL , DENSE_RANK() OVER(ORDER BY SAL DESC ) AS RANKS FROM EMPLOY)
EMPLOY WHERE RANKS=6

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Sks Microfinance

978


my question is : reverse a string in COBOL program (please write a code asap) input file: 1234abcdef output file: 8765_____ abc*$#1___ 1_2_3_4__ cdef____ghi h_k_z_a__ a_z_k_h___ ihg____ghi 4_3_2_1___ 1#$*cba__ ______5678 fedcb4321

1293


i want the sample placement paper of goldman sachs urgently. please send it to me

3923


printf("%d",printf("%d",printf("%d",printf("%s","ILOVECPROGRAM")))); whats the output

1394


What kind of Issues/bugs arise in ETL projects? I would like to know few issues (critical to somewhat bugs ) normally occur in ETL process especially when testing? Domains can be banking, retail or any.

1424






Danlaw placement questions and answers

1352


aptitude

695


how did you celebrate your last birthday?

1271


What are the frequently asked questions for interview in capital iq company ?

1319


why didn't get placed so far?

1190


what is the use of air in gc

1433


email me previous question papers of bob bank for po exams

2059


my question is : reverse a string in COBOL program (please write a code asap) input file: 1234abcdef abc*$#1___ cdef____ghi a_z_k_h___ 4_3_2_1___ ______5678 output file: 8765_____ 1_2_3_4__ h_k_z_a__ ihg____ghi 1#$*cba__ fedcb4321

1190


what is bidirectional?

1387


speak 1min on topic Travelling,memorable moment ,memorable day?

1737