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
Do we have vacancy for HR RECRUITER ?
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
what is bidirectional?
What were the occupations of the people who lived within the Mauryan Empire?
Zero setting of sejong rottary press
Sks Microfinance
If anybody knows the recruitment procedure of IOTL & POWER MECHANICAL. send me the placement papers if u hav... very urgent ...
email me previous question papers of bob bank for po exams
What are the frequently asked questions for interview in capital iq company ?
what is the use of air in gc
i want the sample placement paper of goldman sachs urgently. please send it to me
Danlaw placement questions and answers
Give me Medha Sevo previous written test question papers
your project to describe and tell about : 1. My favorite things 2. My favorite places at home 3. Animals *Choose one of them to describe *Write on your paper *If you done, Send me *Did you get it
HI SIR I WANT PREVIOUS QUESTION PAPER OF HPCL I M CHEMICAL ENGG.