Questions: SQL & Relational DBs
Back to Topics List

SQL & Relational DBs Questions

Page 3 of 3 (Displaying Questions 201 – 215 of 215 Total)

201. Write a query to find employees whose names contain the letter 'x'.

Show Answer

SELECT Name FROM Employees WHERE Name LIKE '%x%';

Added: Nov 30, 2025

202. Write a query to find the smallest price of a product in the 'Hardware' category.

Show Answer

SELECT MIN(Price) FROM Products WHERE Category = 'Hardware';

Added: Nov 30, 2025

203. Write a query to find the total number of rows in the `Log` table.

Show Answer

SELECT COUNT(*) FROM Log;

Added: Nov 30, 2025

204. Write a query to find all customers whose `Name` is the same as their `City`.

Show Answer

SELECT Name, City FROM Customers WHERE Name = City;

Added: Nov 30, 2025

205. Write a query to find customers who placed an order after January 1, 2024.

Show Answer

SELECT * FROM Orders WHERE OrderDate > '2024-01-01';

Added: Nov 30, 2025

206. Write a query to add 5 days to today's date.

Show Answer

SELECT DATE_ADD(CURDATE(), INTERVAL 5 DAY);

Added: Nov 30, 2025

207. Write a query to find all employees who were hired in the year 2023.

Show Answer

SELECT Name FROM Employees WHERE YEAR(HireDate) = 2023;

Added: Nov 30, 2025

208. Write a query to count how many orders were placed by the customer with `CustomerID` 5.

Show Answer

SELECT COUNT(*) FROM Orders WHERE CustomerID = 5;

Added: Nov 30, 2025

209. Write a query to find all products that have the letter 'e' as the third character.

Show Answer

SELECT ProductName FROM Products WHERE ProductName LIKE '__e%';

Added: Nov 30, 2025

210. What is the purpose of the `LIMIT` clause?

Show Answer

The `LIMIT` clause is used to restrict the number of rows returned by a SELECT statement.

Added: Nov 30, 2025

211. How do you update the `Status` of all orders that are older than 30 days to 'Archived'?

Show Answer

UPDATE Orders SET Status = 'Archived' WHERE OrderDate < DATE_SUB(CURDATE(), INTERVAL 30 DAY);

Added: Nov 30, 2025

212. What is normalization in databases?

Show Answer

Normalization is the process of organizing the columns and tables in a database to reduce data redundancy (duplicate data) and improve data integrity (accuracy).

Added: Nov 30, 2025

213. Write a query to find the department name for the employee with `EmployeeID` 1.

Show Answer

SELECT d.DepartmentName FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID WHERE e.EmployeeID = 1;

Added: Nov 30, 2025

214. Write a query to find all unique first names of customers (assuming you have a `FirstName` column).

Show Answer

SELECT DISTINCT FirstName FROM Customers;

Added: Nov 30, 2025

215. What is a composite index?

Show Answer

A composite index is an index created on two or more columns of a table, often used to speed up queries that involve those specific column combinations.

Added: Nov 30, 2025