SQL Exercises for Practice

Practice SQL questions to enhance our skills in database querying and manipulation. Each question covers a different aspect of SQL, providing a comprehensive learning experience.

We have covered a wide range of topics in the sections beginner, intermediate and advanced.

  1. SQL Practice Exercises for Beginners
    1. Basic Retrieval
    2. Filtering
    3. Arithmetic Operations and Comparisons:
    4. Formatting
    5. Aggregation Functions
  2. SQL Practice Exercises for Intermediate
    1. Group By and Having
    2. Joins
    3. Window Functions
    4. Conditional Statements
    5. DateTime Operations
  3. SQL Practice Exercises for Advanced
    1. Creating and Aliasing
    2. Subqueries
    3. Indexing
    4. Constraints
    5. Views
    6. Stored Procedures:
    7. Transactions

let’s create the table schemas and insert some sample data into them.

Create Sales table

-- Create Sales table

CREATE TABLE Sales (
    sale_id INT PRIMARY KEY,
    product_id INT,
    quantity_sold INT,
    sale_date DATE,
    total_price DECIMAL(10, 2)
);

-- Insert sample data into Sales table

INSERT INTO Sales (sale_id, product_id, quantity_sold, sale_date, total_price) VALUES
(1, 101, 5, '2024-01-01', 150.00),
(2, 102, 3, '2024-01-02', 90.00),
(3, 103, 2, '2024-01-02', 60.00),
(4, 104, 4, '2024-01-03', 120.00),
(5, 105, 6, '2024-01-03', 180.00);

Output:

Create Products table

-- Create Products table

CREATE TABLE Products (
    product_id INT PRIMARY KEY,
    product_name VARCHAR(100),
    category VARCHAR(50),
    unit_price DECIMAL(10, 2)
);

-- Insert sample data into Products table

INSERT INTO Products (product_id, product_name, category, unit_price) VALUES
(101, 'Laptop', 'Electronics', 500.00),
(102, 'Smartphone', 'Electronics', 300.00),
(103, 'Headphones', 'Electronics', 30.00),
(104, 'Keyboard', 'Electronics', 20.00),
(105, 'Mouse', 'Electronics', 15.00);

Output:

SQL Exercises

SQL (Structured Query Language) is a powerful tool used for managing and manipulating relational databases. Whether we are beginners or experienced professionals, practicing SQL exercises is essential for our skills and language mastery.

In this article, we’ll cover a series of SQL practice exercises covering a wide range of topics suitable for beginners, intermediate, and advanced learners. These exercises are designed to provide hands-on experience with common SQL tasks, from basic retrieval and filtering to more advanced concepts like joins window functions, and stored procedures.

List of SQL Exercises

  • SQL Questions for Practice
  • SQL Practice Exercises for Beginners
  • SQL Practice Exercises for Intermediate
  • SQL Practice Exercises for Advanced
  • More Questions For Practice

Similar Reads

SQL Exercises for Practice

Practice SQL questions to enhance our skills in database querying and manipulation. Each question covers a different aspect of SQL, providing a comprehensive learning experience....

SQL Practice Exercises for Beginners

This hands-on approach provides a practical environment for beginners to experiment with various SQL commands, gaining confidence through real-world scenarios. By working through these exercises, newcomers can solidify their understanding of fundamental concepts like data retrieval, filtering, and manipulation, laying a strong foundation for their SQL journey....

SQL Practice Exercises for Intermediate

These exercises are designed to challenge you beyond basic queries, delving into more complex data manipulation and analysis. By tackling these problems, you’ll solidify your understanding of advanced SQL concepts like joins, subqueries, functions, and window functions, ultimately boosting your ability to work with real-world data scenarios effectively....

SQL Practice Exercises for Advanced

This section likely dives deeper into complex queries, delving into advanced features like window functions, self-joins, and intricate data manipulation techniques. By tackling these challenging exercises, users can refine their SQL skills and tackle real-world data analysis scenarios with greater confidence and efficiency....

More Questions For Practice

If you’re looking to sharpen your SQL skills and gain more confidence in querying databases, consider delving into these articles. They’re packed with query-based SQL questions designed to enhance your understanding and proficiency in SQL....

Conclusion

Mastering SQL requires consistent practice and hands-on experience. By working through these SQL practice exercises, you’ll strengthen your skills and gain confidence in querying relational databases....