Class Mock Interview
Class Mock Interview
1.What types of SQL statements or languages (or SQL subsets) do you know?
Data Definition Language (DDL) – to define and modify the structure of a database.
Data Manipulation Language (DML) – to access, manipulate, and modify data in a database.
Data Control Language (DCL) – to control user access to the data in the database and give or revoke
privileges to a specific user or a group of users.
Data Query Language (DQL) – to perform queries on the data in a database to retrieve the necessary
information from it.
DQL: – SELECT
PRIMARY KEY – allows only unique and strictly non-null values (NOT NULL and UNIQUE).
3.What is a subquery?
Also called an inner query, a query placed inside another query, or an outer query. A subquery may
occur in the clauses such as SELECT, FROM, WHERE, UPDATE, etc. It's also possible to have a
subquery inside another subquery. The innermost subquery is run first, and its result is passed to the
containing query (or subquery).
What types of SQL subqueries do you know?
WHERE Clause is used to filter the records from the HAVING Clause is used to filter record from the
table based on the specified condition groups based on the specified condition.
WHERE Clause can be used without GROUP BY HAVING Clause cannot be used without GROUP BY
Clause Clause
We use where clause before group by We use having clause after group by
We cannot use aggregate function in where clause We must have to use aggregate functions
WHERE Clause can be used with SELECT, UPDATE, HAVING Clause can only be used with SELECT
DELETE statement. statement.
We can apply where clause with We can’t apply where clause with We can’t apply where clause with
delete command drop command truncate command.
Syntax: DELETE from WHERE ; Syntax: drop table empinfo3 Syntax: truncate table empct10
Que 6.Explain not null constraint
Not null-- It does not accept nulls value but accepts duplicates
Create table CT10INFOCONS2 (cid number (7),cname varchar2(20) not null,cmob varchar2(14),cbill
number(5), ccity varchar2(20));
Que.7 In which order the interpreter executes the common statements in the
SELECT query?
FROM – JOIN – ON – WHERE – GROUP BY – HAVING – SELECT – ORDER BY – LIMIT
Que 9.Given a table employee in which we have DeptId for each employee
write single query from to move the employees from deptid1 to deptid2 and
move employee from deptid 2 to 1
Employee
ID Name dept id
1. John 1
2. Prashant 2
3. Vishal 1
4. Pritesh 2
Tricky Interview Questions to confuse Candidates
Designed to challenge the solver in you, these questions will assess your problem-solving skills. Use
the table below for refrence and answer the questions accordingly.
Orders Table:
Order ID Customer ID Order Date Order Total
100 1 2023-07-01 100.00
101 2 2023-06-15 50.00
102 3 2023-07-05 150.00
103 1 2023-07-07 75.00
104 4 2023-07-02 200.00
Que10.Find the total number of orders placed by each customer, excluding
orders placed in June.
Tricky Aspect: Excluding a specific month required filtering based on the date.
Answer:
SQL Code:
SELECT c.name, COUNT(*) AS num_orders
FROM Customers c
INNER JOIN Orders o ON c.customer_id = o.customer_id
WHERE MONTH(order_date) <> 6
GROUP BY c.name
Que.12 Write a query to display the top 2 customers with the most orders in
the last 30 days.
Tricky Aspect: Requires filtering by date range and using window functions for ranking.
Answer:
SQL Code:
SELECT c.name, COUNT(*) AS num_orders
FROM Customers c
INNER JOIN Orders o ON c.customer_id = o.customer_id
WHERE order_date >= DATE_SUB (CURDATE)
UNION ALL – returns the records obtained by at least one of two queries (including duplicates)
EXCEPT (called MINUS in MySQL and Oracle) – returns only the records obtained by the first query
but not the second one
Que 14.How many records returns from following table using different join
types
Que15.How do you find all employee who are also manager? Which types of
join used and why?
Using self-join
Que.16 Find all employee names starting with ‘S’ not using like operator
Ans : using INSTR select ename from emp where instr(ename,’S’)=1;
What are some steps involved in the working of the Incident management
system? Or Steps for handling the incident
Acknowledgement Basic investigation Creation of incident ticket Sending communication to
business and end user about the incident Opening bridge call Engaging required person
Investigation and diagnostics Periodically sending update notification Escalation if required
(Functional/Hierarchical) Resolution\Workaround (Server restarts) Root Cause (Server in hang
status) Sending final notification to business and customer Confirming the solution and closing
the ticket\