Embarking on your SQL learning journey with Kaggle's 'Introduction to SQL' exercise series? You're excelling with 'Exercise 3'! This interactive session dives you into managing complex queries and manipulating data using the powerful Structured Query Language (SQL).

Priorΰ§ΰ¦Ήave some SQL basics up your sleeve, feel confident to tie it all together in this exercise. By now, you should be comfortable with SELECT, WHERE, AND, OR, NOT, and some basic data types. If you're unsure, revisit previous exercises to strengthen your foundation.

Complex Queries and Subqueries
'Exercise 3' introduces you to complex queries and subqueries, allowing you to probe deeper into data. Prepare to get comfortable with the ')' and '(' parentheses!

A subquery is a query nested inside another query. It executes before the main query, with its results used to filter records. Sounds intricate? Let's break it down.
Correlated Subqueries

Correlated subqueries rely on values from the outer query to determine their results. These subqueries use a keyword FIRST, LAST, ALL, or ANY with an operator (=, <>, <, >, <=, >=, between, in, like, or not in).
Imagine you're managing a retail store. You need to find products where the quantity is greater than the average quantity of products in the same category. A correlated subquery can retrieve this data by comparing each product with the average:
Non-Correlated Subqueries

Non-correlated subqueries don't rely on values from the outer query. Instead, they use constants or columns from the same table. These subqueries are 'self-contained', using the keywords FIRST, LAST, ALL, or ANY with a specific comparison operator as mentioned earlier.
Suppose you're maintaining a customer database and want to find out how many customers are older than the oldest customer in your database. A non-correlated subquery can yield this result by comparing each customer's age with a constant:
Data Manipulation

'Exercise 3' isn't just about querying; it also delves into data manipulation using INSERT, UPDATE, and DELETE statements.
Here you'll practice amending data in your tables to match the current scenario. Let's say you've updated your product prices due to inflation. You can use an UPDATE statement to reflect these changes in your database:



















INSERT Statement
The INSERT statement adds new records into a table. You can add one record at a time or multiple records using a VALUES clause.
Suppose you're launching a new product line in your store. To add these products to your inventory, you can use the INSERT statement:
DELETE Statement
The DELETE statement removes existing records from a table. Be cautious when using this statement, as deleted records can't be retrieved.
Fallible humans make mistakes, and sometimes, data discrepancies occur in your database. A DELETE statement can remove such erroneous entries:
As you conclude 'Exercise 3', you're now capable of crafting complex queries and manipulating data using SQL. The best part? This is just the beginning! Continuously practice, and you'll be an SQL maestro in no time. So, what's next on your SQL learning adventure?