1. Trang chủ
  2. » Công Nghệ Thông Tin

Most asked sql interview questions

33 0 0
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Most asked sql interview questions
Thể loại tài liệu
Định dạng
Số trang 33
Dung lượng 5,72 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

returns only the rows where there is a match in both tables.. A ‘LEFT JOIN’ returns all rows from the left table and matched rows from the right table, and ‘NULL?’ for non-matching row

Trang 1

MOST ASKED

at MAANG Companies

Structured Query Lance 3uage

Trang 2

Medium-Level SQL Questions

Q1

Explain the difference between INNER JOIN

and LEFT JOIN

Ans

An ‘INNER JOIN’? returns only the rows where there is a

match in both tables A ‘LEFT JOIN’ returns all rows

from the left table and matched rows from the right table, and ‘NULL?’ for non-matching rows in the right table

Q2

What is the purpose of the GROUP BY

clause?

Ans

The GROUP BY clause groups rows that have the same

values in specified columns into summary rows, like "find

the number of customers in each country."

Trang 4

Q5

Explain the concept of a ‘VIEW’ in SQL

Ans

A ‘VIEW’ is a virtual table based on the result set of an

SQL query It can simplify complex queries, improve

security by restricting data access, and present a

consistent, logical view of the data

Q6

What is a ‘UNION’ operator?

Ans

The ‘UNION’ operator is used to combine the result sets

of two or more ‘SELECT’ statements Each ‘SELECT’

Statement must have the same number of columns in the result sets with similar data types.

Trang 5

Q7

Ans

Ớ Copy code name,

Trang 6

Q9

Describe the use of ‘TRIGGERS’ in SQL

Ans

Triggers are database objects that automatically execute

a specified SQL procedure when a certain event occurs

on a table or view, such as an ‘INSERT’, ‘UPDATE’, or

‘DELETE’

Q10

Explain the concept of ‘NORMALIZATION

Ans

Normalization is the process of organizing data ina

database to reduce redundancy and improve data

integrity It involves dividing large tables into smaller ones and defining relationships between them.

Trang 7

SalesPerson

Sales_CTE;

Trang 8

G12

Explain the differences between ‘DELETE’,

‘TRUNCATE’, and ‘DROP’ commands

Ans

‘DELETE’ Removes rows one at a time and logs individual row deletions It can include a WHERE clause

"TRUNCATE’: Removes all rows from a table without

logging individual row deletions Cannot include a

"WHERE’ clause

‘DROP’: Removes a table from the database entirely,

including its structure

Q13

How do you optimize a slow-running query?

Ans

Techniques include indexing, query rewriting, reducing

the number of joins, avoiding SELECT * and analyzing the execution plan.

Trang 9

Q14

Ans

(} Copy code

name, department, salary,

Trang 11

Q18

Explain the concept of ‘sharding’ in

databases

Ans

Sharding is a type of database partitioning that splits

large databases into smaller, more manageable pieces,

called shards, which can be spread across multiple

Stored procedures are precompiled collections of SQL

Statements stored under a name and processed as a unit They can accept parameters and are used to perform

tasks like data validation or access control

11

Trang 12

Q20

Explain the concept of ‘Data Warehousing’

Ans

Data warehousing involves the collection, storage, and

management of large volumes of data from multiple

sources to provide meaningful business insights It

typically involves ETL processes and uses schemas like

Star or snowflake schema

12

Trang 13

Employee Management System

Tables:

e Employees

Œ Copy code

Employees ( EmployeeID -''ˆ KEY,

Trang 14

Questions:

Q21

Ans

(Salary) SecondHighestSalary Employees

Salary < (

Q22

Ans

< Employees HireDate >= DATEADD(

Trang 15

Q23

Ans

d.DepartmentName, Employees e

Employees e

T(e.EmployeelID) EmployeeCount

d.DepartmentID = e.DepartmentID d.DepartmentName;

Trang 16

Online Retail Database

OrderID -'.,

ProductID ''.ˆ,

Quantity LN,

Price DECIMAL(10, 2)

Trang 17

e Products

Products ( ProductID KEY,

Trang 18

Orders o

p od.ProductID = p.ProductID od.OrderID = o.OrderlID

TotalSold

o.OrderDate >= DATEADD( ; GETDATE())

p.ProductName TotalSold

() Copy code

18

Trang 19

od.ProductID = p.ProductID p.CategoryID = c.CategoryID c.CategoryName;

Q27

Ans

CustomerTD Orders

OrderDate >= DATEADD( , GETDATE());

Trang 21

Orders

DATE_FORMAT (OrderDate,

DATE_FORMAT

DATE_FORMAT

Trang 22

LEFT JOIN OrderDetails od ON p.ProductID = od.ProductID

EFT JOIN Orders o ON od.OrderID = o.OrderID AND o.OrderDate >= DATEADD

Trang 24

Ans

Copy code

ProductAvailability ( ProductiTD -'.ˆ,

b.StartDate < a.EndDate

a.StartDate <> b.StartDate;

Trang 25

Q3/7

Ans

CustomerID, Orders

CustomerID;

Q38

Ans

p.ProductName, Products p

OrderDetails od

X(OxderDate ) MostRecentOrderDate

(od.Quant1ty) TotalOrdered

p.ProductID = od.ProductID p.ProductName

Trang 26

Q59

Ans

ConsecutiveOrders

CustomerID, OrderDate,

Trang 27

Œ Copy code

27

Trang 29

Q42

Ans

sql

CREATE TABLE Employees (

EmployeeTD PRIMARY KEY, F2 1< (50),

SELECT * FROM EmployeeHierarchy

ORDER BY Level, ManagerID;

Œ Copy code

29

Trang 30

/ LAG(SUM(TotalAmount), i) OVER (ORDER BY YEAR(OrderDate)) * 3

Trang 31

Q45

Ans

mysqldump -u source_user -p source_db > source_db.sql

mysql -u target_user -p target_db < source_db.sql

Ớ Copy code

Ớ Copy code

31

Trang 32

200.00);

Trang 33

Ans

ŒỞ Copy code

OrderDate, TotalAmount, SUM(TotalAmount } OrderDate) Runn1ngTotal Orders;

Ans

Œ Copy code

CustomerTD Customers

CustomerTD Í

CustomerlD Orders

OrderDate >= DATEADD( ree a) ep

Ngày đăng: 11/05/2025, 16:54

w