Real SQL questions
On Sale
$4.00
$4.00
Basic SQL Questions
- Write a query to select all columns from a table Employees where salary > 50000.
- Write a query to find the second highest salary in the Employees table.
- Write a query to count the number of employees in each department.
- Write a query to find employees whose name starts with 'A'.
- Write a query to update the salary of all employees in department 10 by 10%.
Intermediate SQL Questions
- Write a query to find employees who do not have a manager.
- Write a query to find the top 3 highest paid employees in each department.
- Write a query to delete duplicate rows from a table but keep one copy.
- Write a query to find employees who joined in the last 3 months.
- Write a query to get the total salary for each department, including departments with no employees.
Advanced SQL Questions
- Write a query to find employees whose salary is above the average salary of their department.
- Write a query to pivot data, showing total sales for each product per month.
- Write a query to find the department with the highest number of employees.
- Write a query to identify gaps in a sequence of IDs in a table.
- Write a query to find employees who earn more than their manager.
Scenario-Based / Real-Life SQL
- You have a Sales table with OrderID, CustomerID, OrderDate, Amount. Write a query to get total monthly sales for the last year.
- You have Users and Orders tables. Write a query to find users who haven’t placed any orders.
- You have Products and Inventory tables. Write a query to find products that are out of stock.
- You have Transactions table. Write a query to find suspicious transactions above $10,000.
- Write a query to merge two tables (upsert) in SQL.