Objective: π Learn how to retrieve data from a database and filter it according to specific conditions.
Letβs first learn what is a SQL Query -
A SQL query is a structured command used to retrieve, modify, or manage data in a database.
SELECT
: This is like highlighting a particular column or multiple columns in our spreadsheet. In this case we are retrieving all the data from the column βtitleβ. We will only see the values from βtitleβ column (aka field) -
SELECT title FROM movies_sheet;
WHERE
: Helps us filter out data. It's like using the filter option on our spreadsheet to only show movies released after 2000.
SELECT * FROM movies_sheet WHERE release_year > 2000;
Alright! Now that you've got a hang of how SELECT and WHERE play out, let's crank things up a notch. Ready?
Introduction: πΌ Imagine you're a data analyst at a popular electronics store. You need to pull out relevant data to answer business questions and make informed decisions. Using SQL, you can fetch and filter the data you need!
1οΈβ£ Exploring the Database
Task: π Use the SELECT
statement to view all columns of the**products
** table.
Sample Question: "π List all the products and their attributes available in our store."
Solution:SELECT * FROM products;
Sample Output:
<aside> π‘ Note: We will keep showing you sample results enough to help you visualize the final output for the rest of the course.
</aside>
2οΈβ£ Select Specific Columns
**Sample Question:** "π List the **name** and **price** of all **products**."
Solution:SELECT product_name, price FROM products;
3οΈβ£ Filtering with WHERE