What is the result of a CROSS JOIN between a table with 5 rows and a table with 3 rows?
3 rows
15 rows
8 rows
5 rows
You are tasked with finding the total sales for each month of the year. You have a table 'Orders' with columns 'OrderID', 'OrderDate', and 'SalesAmount'. Which query correctly calculates the monthly sales totals?
SELECT STRFTIME('%Y-%m', OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders GROUP BY Month;
SELECT MONTH(OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders GROUP BY Month;
SELECT EXTRACT(MONTH FROM OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders ORDER BY Month;
SELECT MONTH(OrderDate) AS Month, SUM(SalesAmount) AS TotalSales FROM Orders ORDER BY MONTH(OrderDate);
You want to retrieve products from a 'Products' table where the product name starts with 'App' and ends with 'e'. Which query will give you the correct result?
SELECT * FROM Products WHERE ProductName IN ('App', 'e');
SELECT * FROM Products WHERE ProductName LIKE 'App%e';
SELECT * FROM Products WHERE ProductName LIKE 'App_e';
SELECT * FROM Products WHERE ProductName BETWEEN 'App' AND 'e';
You have a table 'Orders' with columns 'OrderID', 'CustomerID', and 'OrderDate'. You want to rank customers within each order date based on the order they placed (earliest to latest). Which window function should you use?
ROW_NUMBER() OVER (PARTITION BY OrderDate ORDER BY OrderID)
DENSE_RANK() OVER (PARTITION BY CustomerID ORDER BY OrderDate)
RANK() OVER (ORDER BY OrderDate, OrderID)
NTILE(4) OVER (PARTITION BY OrderDate ORDER BY OrderID)
What is a CTE (Common Table Expression) in SQL?
A type of index used for optimizing query performance.
A permanent table structure stored in the database.
A temporary, named result set that can be referenced within a single query.
A stored procedure used to encapsulate and reuse SQL code.
What is the primary difference between a FULL OUTER JOIN and a UNION ALL operation in SQL?
FULL OUTER JOIN eliminates duplicates, UNION ALL retains them.
There is no difference; they achieve the same outcome.
FULL OUTER JOIN combines rows based on a join condition, UNION ALL appends all rows.
FULL OUTER JOIN only returns matching rows, UNION ALL returns all rows from both tables.
You have a table named 'Orders' with columns 'OrderID' and 'CustomerID'. You need to find the customers who have placed more than 5 orders. Which query achieves this using a subquery in the FROM clause?
SELECT DISTINCT CustomerID FROM Orders WHERE OrderID IN (SELECT OrderID FROM Orders GROUP BY OrderID HAVING COUNT(*) > 5)
SELECT CustomerID FROM (SELECT CustomerID, COUNT(*) AS OrderCount FROM Orders GROUP BY CustomerID) AS CustomerOrders WHERE OrderCount > 5
SELECT CustomerID FROM Orders GROUP BY CustomerID HAVING COUNT(*) > 5
SELECT CustomerID FROM Orders WHERE EXISTS (SELECT 1 FROM Orders WHERE CustomerID = Orders.CustomerID GROUP BY CustomerID HAVING COUNT(*) > 5)
You need to find all employees who share the same job title as their manager. Which join operation is MOST suitable for this scenario?
Self-JOIN
LEFT JOIN
FULL OUTER JOIN
CROSS JOIN
You have a table of orders and want to calculate the running total of order amounts for each customer, ordered by order date. Which SQL feature would be most efficient for this task?
Cross Join
Self Join
Recursive CTE
Window Function
In SQL, a self-join is used to:
Improve query performance by reducing the number of joins.
Join a table to itself using an alias.
Combine data from multiple tables based on a common column.
Join two tables with different schemas.