SQL Interview Questions Sheet
SQL Interview Questions Sheet
SIDDHARTH SINGH
INSERT
CREATE
ALIAS
Q5
Write a SQL query to fetch “FIRST_NAME” from Worker table
using the alias name as <WORKER_NAME>.
DISTINCT
REPLACE
Q8
Write a SQL query to print the FIRST_NAME from Worker
table after replacing ‘a’ with ‘A’.
CONCAT
Q 10 Write a SQL query to print all Worker details from the Worker table
order by FIRST_NAME Ascending.
ORDER BY
IN
Q 12
Write a SQL query to print details for Workers with the first
name as “Rahul” and “Lavesh” from Worker table.
NOT IN
Q 13
Write a SQL query to print details of workers excluding first
names, “Rahul” and “Lavesh” from Worker table.
LIKE %
LIKE %
Q 16
Write a SQL query to print details of the Workers whose
FIRST_NAME ends with 'n’.
LIKE _
Q 17
Write a SQL query to print details of the Workers whose
FIRST_NAME ends with ‘l’ and contains five alphabets.
Q 18 Write a SQL query to print details of the Workers whose SALARY lies
between 100000 and 500000.
DATE
DATE
Following SQL Server query returns the current date and time:
SELECT getdate();
GROUP BY
GROUP BY
GROUP BY
Q 25 Write a SQL query to fetch the departments that have less than five
people in it.
UNION ALL
Q 28 Write
table.
a SQL query to show the second highest salary from a
Q 29 Write a SQL query to show the top n (say 10) records of a table.
Following MySQL query will return the top n records using the
LIMIT method:
SELECT * FROM Worker ORDER BY Salary DESC LIMIT 10;
Following SQL Server query will return the top n records using the
TOP command:
SELECT TOP 10 * FROM Worker ORDER BY Salary DESC;
Following Oracle query will return the top n records with the help
of ROWNUM:
SELECT * FROM (SELECT * FROM Worker ORDER BY Salary DESC)
WHERE ROWNUM <= 10;
LIMIT / TOP
Q 31 Write a SQL query to determine the 3rd highest salary without using
TOP or limit method.
SELECT Salary
FROM Worker W1
WHERE 2 = (
SELECT COUNT( DISTINCT ( W2.Salary ) )
FROM Worker W2
WHERE W2.Salary >= W1.Salary
);
Use the following generic method to find nth highest salary
without using TOP or limit.
SELECT Salary
FROM Worker W1
WHERE n-1 = (
SELECT COUNT( DISTINCT ( W2.Salary ) )
FROM Worker W2
WHERE W2.Salary >= W1.Salary
);
CORRELATED SUBQUERY:
CORRELATED SUBQUERY:
CROSS JOIN
Q 36 Managers.
Write a SQL query to print details of the Workers who are also
INNER JOIN
Q 37 Write a SQL query to find the first name, last name, salary,
and job grade for all employees.
INNER JOIN
VIEW
LINK