{"id":111710,"date":"2025-09-04T12:40:52","date_gmt":"2025-09-04T07:10:52","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=111710"},"modified":"2025-09-04T12:25:54","modified_gmt":"2025-09-04T06:55:54","slug":"sql-exercises","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/","title":{"rendered":"SQL Exercises"},"content":{"rendered":"\n<style>\n        \/* General styles *\/\n        .sql-input {\n            border-bottom: 1px dashed #9CA3AF !important;\n        }\n        .sql-input:focus {\n            outline: none;\n            background-color: #E0E7FF;\n            border-bottom: 1px solid #3B82F6;\n        }\n\n        .sql-select {\n            font-family: monospace;\n            background-color: #F3F4F6;\n            border: 1px dashed #9CA3AF;\n            font-size: 0.875rem; \/* 14px *\/\n            color: #1D4ED8;\n            border-radius: 4px;\n            padding: 1px;\n        }\n        .sql-select:focus {\n            outline: none;\n            border: 1px solid #3B82F6;\n        }\n        \n        .sql-query-template {\n            background-color: #F9FAFB;\n            padding: 1rem;\n            border-radius: 0.375rem;\n            font-family: monospace;\n            font-size: 0.95rem;\n            color: #374151;\n            line-height: 1.6;\n        }\n\n        \/* NEW: CSS class for topic buttons for cleaner HTML and hover effects *\/\n        .topic-item-btn {\n            background-color: #FFFFFF;\n            padding: 1.5rem;\n            border-radius: 0.5rem;\n            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n            text-align: left;\n            width: 100%;\n            border: 1px solid #E5E7EB;\n            cursor: pointer;\n            transition: all 0.2s ease;\n        }\n        .topic-item-btn:hover {\n            transform: translateY(-3px);\n            box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);\n                background-color: white;\n\n        }\n    <\/style>\n\n\n<div class=\"sql-ex-container\" style=\"font-family: sans-serif; background-color: #FFFFFF; color: #1F2937; max-width: 56rem; width: 100%; margin: 2rem auto; border-radius: 1rem; padding: 1.5rem;\">\n\n    <div id=\"sql-ex-topic-selection-view\">\n        <h1 style=\"font-size: 1.875rem; line-height: 2.25rem; font-weight: 700; text-align: center; color: #111827; margin-bottom: 0.5rem;\" style=\"font-size: 1.875rem; line-height: 2.25rem; font-weight: 700; text-align: center; color: #111827; margin-bottom: 0.5rem;\" id=\"sql-practice-exercises\">SQL Practice Exercises<\/h1>\n        <p style=\"text-align: center; color: #6B7280; margin-bottom: 2rem;\">Solve 80+ SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.<\/p>\n\n        <div id=\"sql-ex-topic-grid\" style=\"display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.5rem;\">\n            \n            <button class=\"topic-item-btn\" data-topic-key=\"BasicSELECTStatements\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"basic-select-statements\">Basic SELECT Statements<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"FilteringwithWHERE\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"filtering-with-where\">Filtering with WHERE<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"SortingwithORDERBY\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"sorting-with-order-by\">Sorting with ORDER BY<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"AggregateFunctions\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"aggregate-functions\">Aggregate Functions<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"GroupingwithGROUPBY\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"grouping-with-group-by\">Grouping with GROUP BY<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"INNERJOIN\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"inner-join\">INNER JOIN<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"LEFTJOIN\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"left-join\">LEFT JOIN<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"RIGHTJOIN\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"right-join\">RIGHT JOIN<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Subqueries\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"subqueries\">Subqueries<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"UNIONandUNIONALL\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"union-and-union-all\">UNION and UNION ALL<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"CASEStatements\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"case-statements\">CASE Statements<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"WorkingwithNULL\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"working-with-null\">Working with NULL<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"StringFunctions\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"string-functions\">String Functions<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"DateandTimeFunctions\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"date-and-time-functions\">Date and Time Functions<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Views\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"views\">Views<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n            <button class=\"topic-item-btn\" data-topic-key=\"Indexes\">\n                <h3 style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" style=\"font-size: 1.25rem; font-weight: 700; color: #1F2937; margin: 0 0 0.25rem 0;\" id=\"indexes\">Indexes<\/h3>\n                <p style=\"color: #6B7280; margin: 0;\">5 exercise questions<\/p>\n            <\/button>\n             <noscript>\n                <p style=\"text-align: center; background-color: #FEF2F2; color: #991B1B; padding: 1rem; border-radius: 0.5rem; grid-column: 1 \/ -1;\">\n                    The interactive exercises on this page require JavaScript. Please enable it in your browser to start practicing.\n                <\/p>\n            <\/noscript>\n        <\/div>\n    <\/div>\n\n    <div id=\"sql-ex-exercise-views-container\">\n        <\/div>\n\n<\/div>\n\n<script>\nconst exercises = {\n    \"Basic SELECT Statements\": [\n        { question: \"Select all columns from the `customers` table.\", template: [ \"SELECT \", { type: \"input\", size: 3, placeholder: \"...\" }, \" FROM \", { type: \"input\", size: 10, placeholder: \"table\" },\";\" ], solution: [\"*\", \"customers\"] },\n        { question: \"Select only the `name` and `email` columns from the `customers` table.\", template: [ \"SELECT \", { type: \"input\", size: 12, placeholder: \"columns\" }, \" FROM customers;\" ], solution: [\"name, email\"] },\n        { question: \"Select all unique cities from the `customers` table.\", template: [ \"SELECT \", { type: \"select\", options: [\"UNIQUE\", \"DISTINCT\"] }, \" city FROM customers;\" ], solution: [\"DISTINCT\"] },\n        { question: \"Select the first 5 rows from the `products` table.\", template: [ \"SELECT * FROM products \", { type: \"input\", size: 6, placeholder: \"clause\" }, \" 5;\" ], solution: [\"LIMIT\"] },\n        { question: \"Select all columns from `orders` and rename the `order_date` column to `date_of_order`.\", template: [ \"SELECT *, order_date \", { type: \"select\", options: [\"AS\", \"IS\", \"TO\"] }, \" date_of_order FROM orders;\" ], solution: [\"AS\"] }\n    ],\n    \"Filtering with WHERE\": [\n        { question: \"Select all products where the price is greater than 50.\", template: [ \"SELECT * FROM products \", { type: \"input\", size: 6, placeholder: \"clause\" }, \" price > 50;\" ], solution: [\"WHERE\"] },\n        { question: \"Select all customers who live in 'London'.\", template: [ \"SELECT * FROM customers WHERE city \", { type: \"select\", options: [\"=\", \"!=\", \"IS\"] }, \" 'London';\" ], solution: [\"=\"] },\n        { question: \"Find all orders that were placed on or after '2023-01-01'.\", template: [ \"SELECT * FROM orders WHERE order_date \", { type: \"input\", size: 2, placeholder: \"op\" }, \" '2023-01-01';\" ], solution: [\">=\"] },\n        { question: \"Select all products that are out of stock (stock_quantity = 0).\", template: [ \"SELECT * FROM products WHERE stock_quantity = \", { type: \"input\", size: 2, placeholder: \"value\" },\";\" ], solution: [\"0\"] },\n        { question: \"Find all customers whose names start with 'J'.\", template: [ \"SELECT * FROM customers WHERE name \", { type: \"input\", size: 4, placeholder: \"op\" }, \" 'J%';\" ], solution: [\"LIKE\"] }\n    ],\n    \"Sorting with ORDER BY\": [\n        { question: \"Select all products, sorted by price in ascending order.\", template: [ \"SELECT * FROM products \", { type: \"input\", size: 9, placeholder: \"clause\" }, \" price \", { type: \"select\", options: [\"ASC\", \"DESC\"] },\";\" ], solution: [\"ORDER BY\", \"ASC\"] },\n        { question: \"Select all customers, sorted by name in descending order.\", template: [ \"SELECT * FROM customers ORDER BY name \", { type: \"select\", options: [\"ASC\", \"DESC\"] },\";\" ], solution: [\"DESC\"] },\n        { question: \"Select all orders, sorted by the most recent `order_date` first.\", template: [ \"SELECT * FROM orders ORDER BY order_date \", { type: \"input\", size: 5, placeholder: \"order\" },\";\" ], solution: [\"DESC\"] },\n        { question: \"Select all products, sorted by `category` and then by `price` in descending order.\", template: [ \"SELECT * FROM products ORDER BY category, price \", { type: \"input\", size: 5, placeholder: \"order\" },\";\" ], solution: [\"DESC\"] },\n        { question: \"Select the top 10 most expensive products.\", template: [ \"SELECT * FROM products ORDER BY price \", { type: \"select\", options: [\"DESC\", \"ASC\"] }, \" \", { type: \"input\", size: 6, placeholder: \"clause\" }, \" 10;\" ], solution: [\"DESC\", \"LIMIT\"] }\n    ],\n    \"Aggregate Functions\": [\n        { question: \"Count the total number of customers.\", template: [ \"SELECT \", { type: \"input\", size: 8, placeholder: \"function\" }, \"(*) FROM customers;\" ], solution: [\"COUNT\"] },\n        { question: \"Find the average price of all products.\", template: [ \"SELECT \", { type: \"select\", options: [\"AVG\", \"MEAN\", \"AVERAGE\"] }, \"(price) FROM products;\" ], solution: [\"AVG\"] },\n        { question: \"Find the total sum of all order amounts.\", template: [ \"SELECT \", { type: \"input\", size: 4, placeholder: \"function\" }, \"(order_amount) FROM orders;\" ], solution: [\"SUM\"] },\n        { question: \"Find the price of the most expensive product.\", template: [ \"SELECT \", { type: \"input\", size: 4, placeholder: \"function\" }, \"(price) FROM products;\" ], solution: [\"MAX\"] },\n        { question: \"Find the price of the cheapest product.\", template: [ \"SELECT \", { type: \"input\", size: 4, placeholder: \"function\" }, \"(price) FROM products;\" ], solution: [\"MIN\"] }\n    ],\n    \"Grouping with GROUP BY\": [\n        { question: \"Count the number of customers in each city.\", template: [ \"SELECT city, COUNT(*) FROM customers \", { type: \"input\", size: 9, placeholder: \"clause\" }, \" city;\" ], solution: [\"GROUP BY\"] },\n        { question: \"Find the average price of products in each category.\", template: [ \"SELECT category, AVG(price) FROM products GROUP BY \", { type: \"input\", size: 9, placeholder: \"column\" },\";\" ], solution: [\"category\"] },\n        { question: \"Find the total order amount for each customer.\", template: [ \"SELECT customer_id, SUM(order_amount) FROM orders GROUP BY \", { type: \"input\", size: 12, placeholder: \"column\" },\";\" ], solution: [\"customer_id\"] },\n        { question: \"Find categories with more than 5 products.\", template: [ \"SELECT category, COUNT(*) FROM products GROUP BY category \", { type: \"input\", size: 7, placeholder: \"clause\" }, \" COUNT(*) > 5;\" ], solution: [\"HAVING\"] },\n        { question: \"Find the total sales for each month from the 'orders' table. (Hint: Use STRFTIME)\", template: [ \"SELECT STRFTIME('\", { type: \"input\", size: 7, placeholder: \"format\" }, \"', order_date) AS month, SUM(order_amount) FROM orders GROUP BY month;\" ], solution: [\"%Y-%m\"] }\n    ],\n    \"INNER JOIN\": [\n        { question: \"Select all orders and the corresponding customer names.\", template: [ \"SELECT orders.*, customers.name FROM orders \", { type: \"select\", options: [\"JOIN\", \"LEFT JOIN\", \"INNER JOIN\"] }, \" customers ON orders.customer_id = customers.id;\" ], solution: [\"INNER JOIN\"] },\n        { question: \"Select all products and their categories' information.\", template: [ \"SELECT products.*, categories.name FROM products INNER JOIN categories \", { type: \"input\", size: 2, placeholder: \"kw\" }, \" products.category_id = categories.id;\" ], solution: [\"ON\"] },\n        { question: \"Show the customer name and the product they ordered using aliases.\", template: [ \"SELECT c.name, p.name FROM customers c \", { type: \"input\", size: 5, placeholder: \"op\" }, \" orders o ON c.id = o.customer_id \", { type: \"input\", size: 5, placeholder: \"op\" }, \" products p ON o.product_id = p.id;\" ], solution: [\"JOIN\", \"JOIN\"] },\n        { question: \"List all employees and the department they work in.\", template: [ \"SELECT e.name, d.name FROM employees e \", { type: \"input\", size: 11, placeholder: \"join clause\" }, \" d \", { type: \"input\", size: 2, placeholder: \"kw\" }, \" e.department_id = d.id;\" ], solution: [\"INNER JOIN departments\", \"ON\"] },\n        { question: \"Get the order details along with the product name for each order.\", template: [ \"SELECT od.*, p.name FROM order_details od JOIN products p ON od.product_id = p.\", { type: \"input\", size: 3, placeholder: \"col\" },\";\" ], solution: [\"id\"] }\n    ],\n    \"LEFT JOIN\": [\n        { question: \"Select all customers and any orders they might have placed.\", template: [ \"SELECT c.name, o.order_date FROM customers c \", { type: \"select\", options: [\"LEFT JOIN\", \"RIGHT JOIN\", \"JOIN\"] }, \" orders o ON c.id = o.customer_id;\" ], solution: [\"LEFT JOIN\"] },\n        { question: \"List all products (even un-ordered ones) and the count of times they have been ordered.\", template: [ \"SELECT p.name, \", { type: \"input\", size: 10, placeholder: \"function\" }, \"(o.id) FROM products p LEFT JOIN orders o ON p.id = o.product_id \", { type: \"input\", size: 9, placeholder: \"clause\" }, \" p.name;\" ], solution: [\"COUNT\", \"GROUP BY\"] },\n        { question: \"Find all departments and the number of employees in each, including departments with no employees.\", template: [ \"SELECT d.name, COUNT(e.id) FROM departments d \", { type: \"input\", size: 10, placeholder: \"join\" }, \" employees e ON d.id = e.department_id GROUP BY d.name;\" ], solution: [\"LEFT JOIN\"] },\n        { question: \"Show all authors and their book titles, including authors who haven't written any books.\", template: [ \"SELECT a.name, b.title FROM authors a LEFT JOIN books b \", { type: \"input\", size: 2, placeholder: \"kw\" }, \" a.id = b.\", { type: \"input\", size: 10, placeholder: \"column\" },\";\" ], solution: [\"ON\", \"author_id\"] },\n        { question: \"List all employees and their managers' names (self-join).\", template: [ \"SELECT e.name AS employee_name, m.name AS manager_name FROM employees e \", { type: \"select\", options: [\"LEFT JOIN\", \"RIGHT JOIN\", \"JOIN\"] }, \" employees m ON e.manager_id = m.id;\" ], solution: [\"LEFT JOIN\"] }\n    ],\n    \"RIGHT JOIN\": [\n        { question: \"Select all orders and the customers who placed them. (This is less common than LEFT JOIN).\", template: [\"SELECT o.*, c.name FROM orders o \", { type: \"select\", options: [\"RIGHT JOIN\", \"LEFT JOIN\", \"JOIN\"] }, \" customers c ON o.customer_id = c.id;\"], solution: [\"RIGHT JOIN\"] },\n        { question: \"List all employees and their departments, including employees not assigned to a department.\", template: [\"SELECT e.name, d.name FROM employees e RIGHT JOIN departments d \", { type: \"input\", size: 2, placeholder: \"kw\" }, \" e.department_id = d.id;\"], solution: [\"ON\"] },\n        { question: \"Show all books and their authors, including books with no listed author.\", template: [\"SELECT b.title, a.name FROM books b \", { type: \"input\", size: 11, placeholder: \"join\" }, \" authors a ON b.author_id = a.id;\"], solution: [\"RIGHT JOIN\"] },\n        { question: \"Get all order details and corresponding products, even if some details don't have a matching product.\", template: [\"SELECT od.*, p.name FROM order_details od RIGHT JOIN products p ON od.\", { type: \"input\", size: 11, placeholder: \"column\" }, \" = p.id;\"], solution: [\"product_id\"] },\n        { question: \"List all projects and the employees assigned to them, including projects with no employees.\", template: [\"SELECT e.name, p.name FROM employees e RIGHT JOIN employee_projects ep ON e.id = ep.employee_id \", { type: \"select\", options: [\"RIGHT JOIN\", \"JOIN\"] }, \" projects p ON ep.project_id = p.id;\"], solution: [\"RIGHT JOIN\"] }\n    ],\n    \"Subqueries\": [\n        { question: \"Find all customers who have placed an order.\", template: [ \"SELECT * FROM customers WHERE id \", { type: \"select\", options: [\"IN\", \"EXISTS\", \"=\"] }, \" (SELECT customer_id FROM orders);\" ], solution: [\"IN\"] },\n        { question: \"Find products with a price higher than the average price.\", template: [ \"SELECT * FROM products WHERE price > (\", { type: \"input\", size: 28, placeholder: \"subquery\" },\");\" ], solution: [\"SELECT AVG(price) FROM products\"] },\n        { question: \"Find customer names who ordered a 'Laptop'.\", template: [ \"SELECT name FROM customers WHERE id IN (SELECT customer_id FROM orders WHERE product_id = (SELECT id FROM products WHERE name = '\", { type: \"input\", size: 8, placeholder: \"item\" }, \"'));\" ], solution: [\"Laptop\"] },\n        { question: \"Find departments that have more than 10 employees.\", template: [ \"SELECT name FROM departments WHERE id IN (SELECT department_id FROM employees \", { type: \"input\", size: 9, placeholder: \"group\" }, \" department_id \", { type: \"input\", size: 7, placeholder: \"having\" }, \" COUNT(*) > 10);\" ], solution: [\"GROUP BY\", \"HAVING\"] },\n        { question: \"Find employees who earn the highest salary in their respective departments (correlated subquery).\", template: [ \"SELECT name, salary FROM employees e1 WHERE salary = (SELECT \", { type: \"input\", size: 4, placeholder: \"func\" }, \"(salary) FROM employees e2 WHERE e1.department_id = e2.department_id);\" ], solution: [\"MAX\"] }\n    ],\n    \"UNION and UNION ALL\": [\n        { question: \"Combine the unique names of all customers and employees.\", template: [ \"SELECT name FROM customers \", { type: \"select\", options: [\"UNION\", \"UNION ALL\", \"COMBINE\"] }, \" SELECT name FROM employees;\" ], solution: [\"UNION\"] },\n        { question: \"Combine product names from 'products' and 'archived_products', including duplicates.\", template: [ \"SELECT name FROM products \", { type: \"select\", options: [\"UNION\", \"UNION ALL\"] }, \" SELECT name FROM archived_products;\" ], solution: [\"UNION ALL\"] },\n        { question: \"List all unique cities where either a customer or a supplier is located.\", template: [ \"SELECT city FROM customers \", { type: \"input\", size: 6, placeholder: \"op\" }, \" SELECT city FROM suppliers;\" ], solution: [\"UNION\"] },\n        { question: \"Combine products with price < 50 and products with price > 100.\", template: [ \"SELECT * FROM products WHERE price < 50 \", { type: \"input\", size: 6, placeholder: \"op\" }, \" SELECT * FROM products WHERE price > 100;\" ], solution: [\"UNION\"] },\n        { question: \"Get a combined list of all active and inactive users, keeping all rows.\", template: [ \"SELECT username, status FROM users \", { type: \"input\", size: 10, placeholder: \"op\" }, \" SELECT username, status FROM inactive_users;\" ], solution: [\"UNION ALL\"] }\n    ],\n    \"CASE Statements\": [\n        { question: \"Categorize products by price: 'Cheap' (< 50), 'Moderate' (50-100), 'Expensive' (> 100).\", template: [ \"SELECT name, CASE WHEN price < 50 THEN 'Cheap' WHEN price \", { type: \"input\", size: 18, placeholder: \"condition\" }, \" THEN 'Moderate' \", { type: \"input\", size: 5, placeholder: \"...\" }, \" 'Expensive' END AS price_category FROM products;\" ], solution: [\"BETWEEN 50 AND 100\", \"ELSE\"] },\n        { question: \"Show 'In Stock' if stock_quantity > 0, and 'Out of Stock' otherwise.\", template: [ \"SELECT name, CASE WHEN stock_quantity > 0 THEN 'In Stock' ELSE '\", { type: \"input\", size: 14, placeholder: \"status\" }, \"' END AS availability FROM products;\" ], solution: [\"Out of Stock\"] },\n        { question: \"Give a 10% discount (x 0.9) to orders over 500.\", template: [ \"SELECT id, CASE WHEN order_amount > 500 THEN order_amount * \", { type: \"input\", size: 4, placeholder: \"val\" }, \" ELSE order_amount END AS discounted_amount FROM orders;\" ], solution: [\"0.9\"] },\n        { question: \"Classify customers as 'New' if their first order was in the last 30 days.\", template: [ \"SELECT name, CASE WHEN first_order_date >= DATE('now', '-30 days') THEN '\", { type: \"input\", size: 4, placeholder: \"type\" }, \"' ELSE 'Existing' END FROM customers;\" ], solution: [\"New\"] },\n        { question: \"Reformat order status: 1 to 'Shipped', 2 to 'Delivered', 0 to 'Pending'.\", template: [ \"SELECT id, CASE status WHEN 1 THEN 'Shipped' WHEN 2 THEN 'Delivered' \", { type: \"select\", options: [\"ELSE\", \"WHEN 0\"] }, \" 'Pending' END AS order_status FROM orders;\" ], solution: [\"ELSE\"] }\n    ],\n    \"Working with NULL\": [\n        { question: \"Find all customers who do not have an email address recorded.\", template: [ \"SELECT * FROM customers WHERE email IS \", { type: \"select\", options: [\"NULL\", \"EMPTY\", \"NOTHING\"] }, \";\" ], solution: [\"NULL\"] },\n        { question: \"Find all products that have a description.\", template: [ \"SELECT * FROM products WHERE description IS \", { type: \"input\", size: 9, placeholder: \"condition\" }, \";\" ], solution: [\"NOT NULL\"] },\n        { question: \"Select all orders, replacing any NULL `shipping_address` with 'N\/A'.\", template: [ \"SELECT id, \", { type: \"input\", size: 9, placeholder: \"function\" }, \"(shipping_address, 'N\/A') FROM orders;\" ], solution: [\"COALESCE\"] },\n        { question: \"Count the number of products missing a price.\", template: [ \"SELECT COUNT(*) FROM products WHERE price \", { type: \"input\", size: 8, placeholder: \"condition\" }, \";\" ], solution: [\"IS NULL\"] },\n        { question: \"If a phone number is NULL, show 'Not Provided'.\", template: [ \"SELECT name, \", { type: \"input\", size: 7, placeholder: \"function\" }, \"(phone_number, 'Not Provided') FROM customers;\" ], solution: [\"IFNULL\"] }\n    ],\n    \"String Functions\": [\n        { question: \"Select the names of all customers in uppercase.\", template: [ \"SELECT \", { type: \"select\", options: [\"UPPER\", \"UCASE\", \"UPPERCASE\"] }, \"(name) FROM customers;\" ], solution: [\"UPPER\"] },\n        { question: \"Find the length of each product name.\", template: [ \"SELECT name, \", { type: \"input\", size: 7, placeholder: \"function\" }, \"(name) FROM products;\" ], solution: [\"LENGTH\"] },\n        { question: \"Concatenate the first and last name of employees.\", template: [ \"SELECT \", { type: \"input\", size: 7, placeholder: \"function\" }, \"(first_name, ' ', last_name) FROM employees;\" ], solution: [\"CONCAT\"] },\n        { question: \"Select the first 3 characters of each customer's city.\", template: [ \"SELECT \", { type: \"input\", size: 10, placeholder: \"function\" }, \"(city, 1, 3) FROM customers;\" ], solution: [\"SUBSTRING\"] },\n        { question: \"Replace all instances of 'Road' with 'Rd.' in the address.\", template: [ \"SELECT \", { type: \"input\", size: 8, placeholder: \"function\" }, \"(address, 'Road', 'Rd.') FROM suppliers;\" ], solution: [\"REPLACE\"] }\n    ],\n    \"Date and Time Functions\": [\n        { question: \"Select the current date and time.\", template: [ \"SELECT \", { type: \"input\", size: 5, placeholder: \"function\" }, \"();\" ], solution: [\"NOW\"] },\n        { question: \"Extract the year from the 'order_date'.\", template: [ \"SELECT \", { type: \"select\", options: [\"EXTRACT\", \"GET\", \"DATE_PART\"] }, \"(YEAR FROM order_date) FROM orders;\" ], solution: [\"EXTRACT\"] },\n        { question: \"Find the number of days between 'shipped_date' and 'order_date'.\", template: [ \"SELECT \", { type: \"input\", size: 8, placeholder: \"function\" }, \"(shipped_date, order_date) FROM orders;\" ], solution: [\"DATEDIFF\"] },\n        { question: \"Add 30 days to the 'order_date' to estimate a delivery date.\", template: [ \"SELECT order_date, \", { type: \"input\", size: 9, placeholder: \"function\" }, \"(order_date, INTERVAL 30 DAY) FROM orders;\" ], solution: [\"DATE_ADD\"] },\n        { question: \"Get the day of the week (e.g., 'Monday') for each order placed.\", template: [ \"SELECT order_date, \", { type: \"input\", size: 8, placeholder: \"function\" }, \"(order_date) FROM orders;\" ], solution: [\"DAYNAME\"] }\n    ],\n    \"Views\": [\n        { question: \"Create a view named 'london_customers' that shows all customers from London.\", template: [ { type: \"input\", size: 12, placeholder: \"statement\" }, \" london_customers AS SELECT * FROM customers WHERE city = 'London';\" ], solution: [\"CREATE VIEW\"] },\n        { question: \"Select all data from the 'london_customers' view.\", template: [ \"SELECT * FROM \", { type: \"input\", size: 17, placeholder: \"view_name\" }, \";\" ], solution: [\"london_customers\"] },\n        { question: \"Create a view that shows the product name and its category name.\", template: [ \"CREATE VIEW product_categories AS SELECT p.name, c.name FROM products p \", { type: \"input\", size: 5, placeholder: \"join\" }, \" categories c ON p.category_id = c.id;\" ], solution: [\"JOIN\"] },\n        { question: \"Update a view named 'customer_emails' to only show the name and email.\", template: [ \"CREATE OR \", { type: \"input\", size: 8, placeholder: \"keyword\" }, \" VIEW customer_emails AS SELECT name, email FROM customers;\" ], solution: [\"REPLACE\"] },\n        { question: \"Delete the 'london_customers' view.\", template: [ { type: \"input\", size: 10, placeholder: \"statement\" }, \" london_customers;\" ], solution: [\"DROP VIEW\"] }\n    ],\n    \"Indexes\": [\n        { question: \"Create an index named 'idx_email' on the 'email' column of the 'customers' table.\", template: [ \"CREATE \", { type: \"input\", size: 6, placeholder: \"type\" }, \" idx_email ON customers (email);\" ], solution: [\"INDEX\"] },\n        { question: \"Create a unique index on the 'product_code' column.\", template: [ \"CREATE \", { type: \"select\", options: [\"UNIQUE\", \"PRIMARY\"] }, \" INDEX idx_product_code ON products (product_code);\" ], solution: [\"UNIQUE\"] },\n        { question: \"Create a composite index on the 'last_name' and 'first_name' columns.\", template: [ \"CREATE INDEX idx_employee_name ON employees (\", { type: \"input\", size: 25, placeholder: \"columns\" }, \");\" ], solution: [\"last_name, first_name\"] },\n        { question: \"Show the existing indexes on the 'orders' table.\", template: [ { type: \"input\", size: 11, placeholder: \"statement\" }, \" FROM orders;\" ], solution: [\"SHOW INDEX\"] },\n        { question: \"Drop the index named 'idx_email' from the 'customers' table.\", template: [ { type: \"input\", size: 11, placeholder: \"statement\" }, \" ON customers;\" ], solution: [\"DROP INDEX idx_email\"] }\n    ]\n};\n\n\ndocument.addEventListener('DOMContentLoaded', function() {\n    const topicSelectionView = document.getElementById('sql-ex-topic-selection-view');\n    const exerciseViewsContainer = document.getElementById('sql-ex-exercise-views-container');\n\n    \/\/ --- Utility Functions ---\n    function normalizeCode(codeStr) {\n        if (typeof codeStr !== 'string') return '';\n        let standardized = codeStr.trim().toLowerCase();\n        if (standardized === 'inner join') return 'join';\n        return standardized.replace(\/\\s+\/g, ' ');\n    }\n    \n    \/\/ --- View Switching Logic ---\n    function showTopicView(topicKey) {\n        topicSelectionView.style.display = 'none';\n        document.querySelectorAll('.sql-ex-exercise-view').forEach(view => view.style.display = 'none');\n        const view = document.getElementById(`sql-ex-view-${topicKey}`);\n        if (view) {\n             view.style.display = 'block';\n        }\n    }\n\n    function showTopicSelection() {\n        topicSelectionView.style.display = 'block';\n        document.querySelectorAll('.sql-ex-exercise-view').forEach(view => view.style.display = 'none');\n    }\n    \n    \/\/ --- Initialization ---\n    function initialize() {\n        const topics = Object.keys(exercises);\n\n        \/\/ Pre-build all Exercise Views (CSR part)\n        topics.forEach(topic => {\n            const topicKey = topic.replace(\/[^a-zA-Z0-9]\/g, '');\n            const questions = exercises[topic];\n\n            let questionsHTML = '';\n            questions.forEach((q, qIndex) => {\n                let templateHTML = '';\n                let inputCounter = 0;\n                q.template.forEach(part => {\n                    if (typeof part === 'string') {\n                        templateHTML += `<span>${part.replace(\/<\/g, \"&lt;\").replace(\/>\/g, \"&gt;\")}<\/span>`;\n                    } else if (part.type === 'input') {\n                        templateHTML += `<input type=\"text\" class=\"sql-input\" id=\"sql-ex-answer-${topicKey}-${qIndex}-${inputCounter}\" size=\"${part.size || 10}\" placeholder=\"${part.placeholder || '...'}\">`;\n                        inputCounter++;\n                    } else if (part.type === 'select') {\n                        const optionsHTML = part.options.map(opt => `<option value=\"${opt}\">${opt}<\/option>`).join('');\n                        templateHTML += `<select class=\"sql-select\" id=\"sql-ex-answer-${topicKey}-${qIndex}-${inputCounter}\">${optionsHTML}<\/select>`;\n                        inputCounter++;\n                    }\n                });\n\n                questionsHTML += `\n                    <div style=\"border: 1px solid #E5E7EB; border-radius: 0.5rem;\">\n                        <div style=\"padding: 1rem; border-bottom: 1px solid #E5E7EB;\">\n                             <p style=\"font-weight: 500; margin:0; color: #374151;\">\n                                <span style=\"font-weight: 700; color: #111827;\">Question ${qIndex + 1}:<\/span> ${q.question}\n                            <\/p>\n                        <\/div>\n                        <div class=\"sql-query-template\">${templateHTML}<\/div>\n                        <div id=\"sql-ex-feedback-${topicKey}-${qIndex}\" style=\"margin-top: 0.5rem; padding: 0 1rem 0.5rem 1rem;\"><\/div>\n                    <\/div>\n                `;\n            });\n\n            const exerciseViewHTML = `\n                <div id=\"sql-ex-view-${topicKey}\" class=\"sql-ex-exercise-view\" style=\"display: none;\">\n                    <div style=\"display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; gap: 1rem;\">\n                        <h2 style=\"font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #111827; margin:0;\" style=\"font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: #111827; margin:0;\" id=\"topic\">${topic}<\/h2>\n                        <button class=\"sql-ex-back-btn\" style=\"background-color: #E5E7EB; color: #374151; font-weight: 500; padding: 0.5rem 1rem; border-radius: 0.5rem; border: none; cursor: pointer;\" onmouseover=\"this.style.backgroundColor='#D1D5DB'\" onmouseout=\"this.style.backgroundColor='#E5E7EB'\">Back to Topics<\/button>\n                    <\/div>\n                    <div style=\"display: flex; flex-direction: column; gap: 1.5rem;\">${questionsHTML}<\/div>\n                    <div id=\"sql-ex-result-container-${topicKey}\" style=\"text-align: center; margin-top: 2rem;\"><\/div>\n                    <div style=\"text-align: center; margin-top: 1.5rem;\">\n                         <button class=\"sql-ex-check-answers-btn\" data-topic-key=\"${topicKey}\" data-topic-name=\"${topic}\" style=\"background-color: #2563EB; color: #FFFFFF; font-weight: 700; padding: 0.75rem 2rem; border-radius: 0.5rem; font-size: 1.125rem; border: none; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\" onmouseover=\"this.style.backgroundColor='#1D4ED8'\" onmouseout=\"this.style.backgroundColor='#2563EB'\">Check Answers<\/button>\n                    <\/div>\n                <\/div>\n            `;\n            exerciseViewsContainer.innerHTML += exerciseViewHTML;\n        });\n\n        \/\/ --- Attach Event Listeners ---\n        \/\/ Attach to the statically rendered topic buttons\n        document.querySelectorAll('.topic-item-btn').forEach(button => {\n            const topicKey = button.getAttribute('data-topic-key');\n            if (topicKey) {\n                button.addEventListener('click', () => showTopicView(topicKey));\n            }\n        });\n\n        \/\/ Attach to the dynamically created back and check-answer buttons\n        document.querySelectorAll('.sql-ex-back-btn').forEach(btn => {\n            btn.addEventListener('click', showTopicSelection);\n        });\n\n        document.querySelectorAll('.sql-ex-check-answers-btn').forEach(btn => {\n            btn.addEventListener('click', (event) => {\n                const topicKey = event.currentTarget.getAttribute('data-topic-key');\n                const topicName = event.currentTarget.getAttribute('data-topic-name');\n                const questions = exercises[topicName];\n                let correctCount = 0;\n\n                questions.forEach((q, qIndex) => {\n                    const feedbackContainer = document.getElementById(`sql-ex-feedback-${topicKey}-${qIndex}`);\n                    let isCorrect = true;\n                    let inputCounter = 0;\n\n                    q.template.forEach(part => {\n                        if (typeof part === 'object') {\n                            const userInputElem = document.getElementById(`sql-ex-answer-${topicKey}-${qIndex}-${inputCounter}`);\n                            const userAnswer = normalizeCode(userInputElem.value);\n                            const correctAnswer = normalizeCode(q.solution[inputCounter]);\n                            if (userAnswer !== correctAnswer) {\n                                isCorrect = false;\n                            }\n                            inputCounter++;\n                        }\n                    });\n\n                    if (isCorrect) {\n                        correctCount++;\n                        feedbackContainer.innerHTML = `<p style=\"color: #16A34A; font-weight: 600; margin:0;\">\u2713 Correct!<\/p>`;\n                    } else {\n                        \/\/ Reconstruct the correct answer string\n                        let correctAnswerHTML = '';\n                        let solutionCounter = 0;\n                        q.template.forEach(part => {\n                            if (typeof part === 'string') {\n                                correctAnswerHTML += `<span>${part.replace(\/<\/g, \"&lt;\").replace(\/>\/g, \"&gt;\")}<\/span>`;\n                            } else {\n                                correctAnswerHTML += `<strong style=\"color: #166534;\">${q.solution[solutionCounter]}<\/strong>`;\n                                solutionCounter++;\n                            }\n                        });\n\n                        feedbackContainer.innerHTML = `\n                            <p style=\"color: #DC2626; font-weight: 600; margin:0;\">\u2717 Incorrect.<\/p>\n                            <p style=\"color: #4B5563; margin-top: 0.25rem; margin-bottom: 0.25rem;\">The correct query is:<\/p>\n                            <pre style=\"background-color: #F0FDF4; color: #1F2937; padding: 0.75rem; border-radius: 0.375rem; font-size: 0.875rem; margin-top: 0.25rem; font-family: monospace; white-space: pre-wrap; word-wrap: break-word;\"><code>${correctAnswerHTML}<\/code><\/pre>\n                        `;\n                    }\n                });\n\n                const resultContainer = document.getElementById(`sql-ex-result-container-${topicKey}`);\n                resultContainer.innerHTML = `\n                    <p style=\"font-size: 1.25rem; font-weight: 700;\">You answered ${correctCount} out of ${questions.length} questions correctly.<\/p>\n                    <p style=\"color: #6B7280; margin-top: 0.25rem;\">Review the feedback above and feel free to try again!<\/p>\n                `;\n            });\n        });\n    }\n\n    \/\/ Run the initialization\n    initialize();\n});\n<\/script>\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>Also Check:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-editor-tool\/\">Online SQL Compiler<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-quiz\">SQL Quiz and MCQs<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">SQL Commands<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/\">SQL Interview Questions<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-does-an-sql-developer-do\/\">How to Become a SQL Developer<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.<\/p>\n","protected":false},"author":41,"featured_media":111724,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36844],"class_list":["post-111710","page","type-page","status-publish","has-post-thumbnail","hentry","category-software","tag-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Practice Questions and Online Exercises for Beginners<\/title>\n<meta name=\"description\" content=\"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Exercises\" \/>\n<meta property=\"og:description\" content=\"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"SQL Exercises\",\"datePublished\":\"2025-09-04T07:10:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/\"},\"wordCount\":135,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/sql-exercise.webp\",\"keywords\":[\"sql\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/\",\"name\":\"SQL Practice Questions and Online Exercises for Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/sql-exercise.webp\",\"datePublished\":\"2025-09-04T07:10:52+00:00\",\"description\":\"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/sql-exercise.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/sql-exercise.webp\",\"width\":1408,\"height\":768,\"caption\":\"SQL Exercise\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-exercises\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Exercises\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Practice Questions and Online Exercises for Beginners","description":"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/","og_locale":"en_US","og_type":"article","og_title":"SQL Exercises","og_description":"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"SQL Exercises","datePublished":"2025-09-04T07:10:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/"},"wordCount":135,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp","keywords":["sql"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/","name":"SQL Practice Questions and Online Exercises for Beginners","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp","datePublished":"2025-09-04T07:10:52+00:00","description":"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp","width":1408,"height":768,"caption":"SQL Exercise"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL Exercises"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/09\/sql-exercise-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Solve SQL practice questions, queries, and online exercises to build real-world database skills. Great for beginners preparing for interviews or exams.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=111710"}],"version-history":[{"count":13,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111710\/revisions"}],"predecessor-version":[{"id":111722,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/111710\/revisions\/111722"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/111724"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=111710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=111710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=111710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}