## Introduction
Welcome to Lesson 2.1: Basic SQL Commands. This lesson is part of Module 2: Core Skills - SQL and Data Management in the Data Analytics for Software Developers course. In this lesson, we'll explore key concepts such as understanding the SELECT, FROM, and WHERE clauses, writing simple SQL queries, and filtering data using WHERE conditions. By the end of this lesson, you will be able to write basic SQL queries to retrieve specific data from databases. Let’s get started!
## Main Content
### Understanding SELECT, FROM, and WHERE Clauses
The foundation of SQL (Structured Query Language) lies in its ability to retrieve data from databases using specific commands. The most fundamental of these commands are SELECT, FROM, and WHERE.
- **SELECT**: This command is used to specify the columns that you want to retrieve from a database. Think of it as choosing which pieces of information you wish to display. For example, if you want to see the names and ages of customers, you would begin your query with `SELECT name, age`.
- **FROM**: This command tells the database from which table to pull the specified data. For instance, if your customers' data is stored in a table called "Customers", you would continue your query with `FROM Customers`.
- **WHERE**: This clause allows you to filter records based on specific conditions. Suppose you only want to see the customers who are older than 30. You would add the clause `WHERE age > 30`. 
Putting it all together, a simple SQL query would look like this:
```sql
SELECT name, age 
FROM Customers 
WHERE age > 30;
```
This query retrieves the names and ages of customers who are older than 30.
### Writing Simple SQL Queries
Now that you understand the basic components of SQL queries, let’s look at how to write them effectively. To create a simple query, you should follow the structure of specifying the desired columns, the table name, and any conditions.
Here’s another example: If you want to retrieve the email addresses of customers who live in a specific city, say "New York", your query would be:
```sql
SELECT email 
FROM Customers 
WHERE city = 'New York';
```
In this query, `email` is the column you want, `Customers` is the table, and `WHERE city = 'New York'` is the condition filtering the results.
To enhance your queries, you can also use the **ORDER BY** clause to sort the results. For instance, if you want to list customers in ascending order by their age:
```sql
SELECT name, age 
FROM Customers 
WHERE age > 30 
ORDER BY age ASC;
```
This query retrieves names and ages of customers older than 30 and sorts them by age in ascending order.
### Filtering Data Using WHERE Conditions
The WHERE clause is powerful for filtering data. It allows you to specify conditions that must be met for the records to be included in the results. You can combine multiple conditions using logical operators like AND, OR, and NOT.
For example, if you want to find customers who live in "New York" and are older than 30, you would write:
```sql
SELECT name, email 
FROM Customers 
WHERE city = 'New York' AND age > 30;
```
In this case, both conditions must be true for a customer to appear in the results.
You can also use the OR operator if you want records that meet at least one of several conditions. For instance, to find customers who are either from "New York" or "Los Angeles":
```sql
SELECT name, email 
FROM Customers 
WHERE city = 'New York' OR city = 'Los Angeles';
```
The NOT operator can be used to exclude certain results. For example, if you want to find customers who are NOT from "Los Angeles":
```sql
SELECT name, email 
FROM Customers 
WHERE NOT city = 'Los Angeles';
```
These filtering techniques allow you to tailor your data queries to get the most relevant information based on specific criteria.
## Conclusion
In this lesson, we covered the essential SQL commands: SELECT, FROM, and WHERE. By learning to write simple SQL queries and filter data using WHERE conditions, you are now equipped to retrieve specific information from databases effectively. Understanding these concepts is crucial for navigating data analytics in your role as a software developer. 
As you move forward, you’ll build upon these skills and explore more complex SQL functionalities.
## Reflection Questions
1. How would you modify a SQL query to retrieve only the names of customers who are younger than 25?
2. What would your SQL query look like if you wanted to find all customers who are either from "Chicago" or have an email address ending in "@gmail.com"?
3. Can you explain the difference between using AND and OR in a WHERE clause? How would each affect your query results?