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
what is difference between uv and visible spectroscopy and how to differentiate the drug compounds in uv visible region
printf("%d",printf("%d",printf("%d",printf("%s","ILOVECPROGRAM")))); whats the output
Do we have vacancy for HR RECRUITER ?
Danlaw placement questions and answers
email me previous question papers of bob bank for po exams
what is bidirectional?
what you will do when you struck in traffic ?
why didn't get placed so far?
Hi.. Guys Im pranitha, presently im working in a organisation & im look for job at MNC's like DELL, Delloitte, Bank of America, Genpect, etc., I have completed B.com . Pls help me...
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.
aptitude
Give me Medha Sevo previous written test question papers
Recently conducted Apptitude test
what is placement paper?
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