## Introduction 
Welcome to Lesson 2.2: Basic SQL Syntax and Queries. This lesson is part of Module 2: Core Skills - Data Analysis Techniques in the Data Analytics for Aspiring Data Scientists course. In this lesson, we'll explore the foundational elements of SQL syntax, including how to write basic queries to retrieve and manipulate data. We will cover key topics such as SQL syntax basics—SELECT, FROM, and WHERE statements—writing simple queries to retrieve data, and filtering and sorting data in SQL. By the end of this lesson, you will be able to write basic SQL queries effectively to manage data.
## Main Content 
### SQL Syntax Basics: SELECT, FROM, WHERE 
Structured Query Language, or SQL, is the standard language for managing and manipulating databases. Understanding the basic syntax is crucial for effective data analysis. The three foundational components of SQL statements are the SELECT, FROM, and WHERE clauses.
- **SELECT**: This clause specifies the columns you want to retrieve from a database. For example, if you want to get the names of customers from a customer database, you would write: 
 ```sql
 SELECT customer_name
 ```
- **FROM**: This clause indicates the table from which to retrieve the data. Continuing with the previous example, if you want to select customer names from the "customers" table, it would look like: 
 ```sql
 SELECT customer_name 
 FROM customers
 ```
- **WHERE**: This clause allows you to filter records based on specific conditions. For instance, if you only want to see customer names for customers located in New York, you would add a WHERE clause: 
 ```sql
 SELECT customer_name 
 FROM customers 
 WHERE city = 'New York'
 ```
This combination of SELECT, FROM, and WHERE clauses forms the backbone of most SQL queries.
### Writing Simple Queries to Retrieve Data 
Now that we understand the basic syntax, let's look at how to compose simple queries to retrieve data. Suppose you have a database of products, and you want to find out the names and prices of all products.
Your SQL query would look like this: 
```sql
SELECT product_name, price 
FROM products
```
This statement retrieves the product names and their respective prices from the "products" table. It's essential to choose only the columns you need to streamline the data returned.
You can also retrieve all columns from a table by using the asterisk (*) wildcard. For example: 
```sql
SELECT * 
FROM products
```
However, while it retrieves all data, it’s best practice to specify only the columns you require for better performance and clarity.
### Filtering and Sorting Data in SQL 
Filtering and sorting data helps you analyze and present information more effectively. Using the WHERE clause, you can filter data based on specific criteria.
For example, if you want to find all products priced above $20, your query would be: 
```sql
SELECT product_name, price 
FROM products 
WHERE price > 20
```
To sort the retrieved data, you can use the ORDER BY clause. If you want to sort the products by price in ascending order, you would write: 
```sql
SELECT product_name, price 
FROM products 
WHERE price > 20 
ORDER BY price ASC
```
By using ORDER BY, you can present your results in a more organized manner. You can also sort in descending order by changing ASC to DESC.
These basic SQL operations allow you to manipulate data effectively and support decision-making processes within your organization.
## Conclusion 
In this lesson, we covered the fundamentals of SQL syntax, focusing on the key clauses: SELECT, FROM, and WHERE. You learned how to write simple queries to retrieve specific data and how to filter and sort that data for better analysis. By mastering these skills, you will be better equipped to handle data queries and enhance your data analysis capabilities. In the next lesson, we will delve deeper into more complex SQL operations, including joins and subqueries, which will further expand your data manipulation skills.
## Reflection Questions 
1. How would you write a SQL query to retrieve names of customers who made purchases over $100? 
2. Describe a scenario where filtering data with a WHERE clause could lead to better decision-making in your role. 
3. What is the importance of specifying columns in a SELECT statement rather than using the wildcard *?