70 SQL Queries Interview Questions and Answers

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Q.29 Write an SQL Query for fetching the intersecting details of two tables.

(SELECT * FROM worker) INTERSECT (SELECT * FROM workerclone);

Q.41 Write an SQL query to fetch all the EmpIds which are present in either of the tables - 'EmployeeDetails' and 'EmployeeSalary'.

SELECT

Q.38 Write an SQL query to fetch all those employees who work on Project other than P1.

SELECT * FROM employeesalary WHERE project <> 'P1';

Q.12 Write an SQL query for printing the all details of the worker table which ordered by FIRST_NAME ascending and the DEPARTMENT in descending

SELECT * FROM worker ORDER BY first_name asc, department desc;

Q.11 What is an SQL query for printing all details of the worker table which ordered by FIRST_NAME ascending?

SELECT * FROM worker ORDER BY first_name;

Q.26 What is an SQL Query for only showing odd rows?

SELECT * FROM worker WHERE MOD (worker_id, 2) <> 0;

Q.15 Write an SQL query for printing the details of DEPARTMENT name as "Admin".

SELECT * FROM worker WHERE department like 'Admin%';

Q.13 What is an SQL query to print the details of the workers 'NIHARIKA' and 'PRIYANSHA'.

SELECT * FROM worker WHERE first_name = 'Niharika' AND 'Priyansha';

Q.17 What is an SQL Query for printing the FIRST_NAME of workers whose name ends with 'A'?

SELECT * FROM worker WHERE first_name LIKE ' %A';

Q.16 What is an SQL query for printing the details of workers whose FIRST_NAME Contains 'A'?

SELECT * FROM worker WHERE first_name LIKE '%A%';

Q.18 What is an SQL Query for printing the details of the workers whose FIRST_NAME ends with 'H' and contains six alphabets?

SELECT * FROM worker WHERE first_name LIKE '______H';

Q.14 What is an SQL query printing all details of workers excluding the first names of 'NIHARIKA' and 'PRIYANSHA'

SELECT * FROM worker WHERE first_name NOT IN ('Niharika','Priyansha');

Q.19 Write an SQL Query for printing the details of workers whose SALARY lies between 10000 and 20000.

SELECT * FROM worker WHERE salary BETWEEN 10000 AND 20000;

Q.20 Write an SQL Query for printing the details of workers who joined inFeb'2014

SELECT * FROM worker WHERE year(joining_date) = 2014 and month(joining_date) = 2;

Q.27 What is an SQL Query for only showing even rows?

SELECT * FROM Worker WHERE MOD (worker_id, 2) = 0;

Q.30 What is an SQL Query for showing the details of one table that another doesn't have.

SELECT * FROM worker MINUS SELECT * FROM title;

Q.28 Write an SQL Query for cloning a new table from another table.

SELECT * INTO workerclone FROM worker;

Q.10 What is an SQL query for printing the FIRST_NAME and LAST_NAME into a column named COMPLETE_NAME? (A space char should be used)

SELECT CONCAT(first_name, ' ', last_name) AS 'complete_name') FROM worker;

Q.22 Write an SQL Query for fetching the details of workers with Salaries >= 5000 and <= 10000.

SELECT CONCAT(first_name, ' ', last_name) AS worker_name, salary FROM worker WHERE worker_id IN (SELECT worker_id FROM worker WHERE salary BETWEEN 5000 AND 100000;

Q.33 Write an SQL query to fetch the count of employees working in project 'P1'.

SELECT COUNT(*) FROM EmployeeSalary WHERE project = 'P1';

Q.21 Write an SQL Query for fetching the count of workers in DEOARTMENT with 'Admin'.

SELECT COUNT(*) FROM worker WHERE department = 'Admin';

Q.8 What is an SQL query for fetching the unique values from the DEPARTMENT column and thus printing is the length?

SELECT DISTINCT LENGTH(department) FROM worker;

Q.3 What is an SQL query for fetching the unique values of the column DEPARTMENT from the WORKER table?

SELECT DISTINCT department FROM worker;

Q.24 What is an SQL Query for printing the details of workers who are also managers?

SELECT DISTINCT w.first_name, t.worker_title FROM worker w INNER JOIN title t ON w.worker_id = t.worker_ref_id AND t.worker_title in ('Manager');

Q.32 Write an SQL query to fetch the different projects available from the EmployeeSalary table.

SELECT DISTINCT(project) FROM EmployeeSalary;

Q.31 Write an SQL query to fetch the EmpId and FullName of all the employees working under Manager with id - '986'.

SELECT Empld, FullName FROM EmployeeDetails WHERE managerid = 986;

Q.5 What is an SQL query for finding the position of the alphabet ('A') in the FIRST_NAME column of Ayushi.

SELECT INSTR(first_name, BINARAY'a') FROM worker WHERE first_name = 'Ayushi';

Q.7 Write an SQL Query for printing the DEPARTMENT from Worker Table after the removal of white spaces from the left side.

SELECT LTRIM(department) FROM worker;

Q.34 Write an SQL query to find the maximum, minimum, and average salary of the employees.

SELECT MAX(salary), MIN(salary), AVG(salary) FROM EmployeeSalary;

Q.9 Write an SQL query for printing the FIRST_NAME after replacing 'A' with 'a'.

SELECT REPLACE(first_name, 'a','A') FROM worker;

Q.6 What is an SQL Query for printing the FIRST_NAME from Worker Table after the removal of white spaces from right side.

SELECT RTRIM(first_name) FROM worker;

Q.4 Write an SQL query for printing the first three characters of the column FIRST_NAME.

SELECT SUBSTRING(first_name, 3) FROM worker;

Q.23 What is an SQL Query for fetching the no. of workers in each department in descending order?

SELECT department, COUNT(worker_id) AS no_of_workers FROM worker GROUP BY department ORDER BY no_of_workers DESC

Q.39 Write an SQL query to display the total salary of each employee adding the Salary with Variable value.

SELECT empld, salary+variable AS TotalSalary FROM EmployeeSalary;

Q.37 Write an SQL query to fetch all the employees who either live in California or work under a manager with ManagerId - 321.

SELECT empld, city, managerid FROM employeedetails WHERE city = 'California' OR managerid = 321;

Q.36 Write an SQL query to fetch those employees who live in Toronto and work under manager with ManagerId - 321.

SELECT empld, city, managerid FROM employeedetails WHERE city = 'Toronto' AND managerid = 321;

Q.35 Write an SQL query to find the employee id whose salary lies in the range of 9000 and 15000.

SELECT empld, salary FROM employeesalary WHERE salary BETWEEN 9000 AND 15000;

Q.1 Write an SQL query for fetching "FIRST_NAME" from the WORKER table using <WORKER_NAME> as alias.

SELECT first_name AS worker_name FROM worker;

Q.40 Write an SQL query to fetch the employees whose name begins with any two characters, followed by a text "hn" and ending with any sequence of characters.

SELECT fullname FROM employeedetails WHERE fullname LIKE '__hn%';

Q.2 What is an SQL Query for fetching the "FIRST_NAME" from WORKER table in upper case?

SELECT upper(first_name) FROM worker;

Q.25 Write an SQL Query for fetching the details of duplicate records in some fields.

SELECT worker_title, affected_from, COUNT(*) FROM title GROUP BY worker_title, affected from HAVING COUNT(*) >1;

Q.46 Write an SQL query to fetch the employee full names and replace the space with '-'.

`


Set pelajaran terkait

AEMT Ch 29 Face and Neck injuries

View Set

Abnormal Psychology Chapter 8 conversion disorder

View Set

Macro Economics 2105 Danns UNG Test Study Set

View Set

Pharmacology Prep U Chapter 20 Anxiolytic and Hypnotic Agents

View Set

19. Express coordinate ideas in similar form

View Set

Series 66 Chapter 6 (pls don't let the 6's be some satanic curse I need to pass this)

View Set