Query Structure: Beginner
Netflix captures 500 billion events per day. Every play, pause, and skip across 230 million accounts. Over 80% of what people watch comes from recommendations built on that data, saving Netflix an estimated $1 billion per year in reduced churn. The foundation of all of it? Rows and columns, stored in tables.
Tables, rows, and columns
Read and navigate any database table
| name | country | age |
|---|---|---|
| Maya Santos | Brazil | 28 |
| Emma Brooks | United States | 34 |
| Ravi Menon | India | 26 |
To communicate with a database, we use a language called SQL (Structured Query Language). Instead of telling the database step by step how to find data, you simply describe what you want, and the database figures out the rest. SQL is designed to be human-readable, using words like SELECT and FROM that describe your request in plain English.
SELECT and FROM basics
Pull specific columns from any table
A query is a question; it is a request for the database to retrieve some data in the format that you specify, and show you the results. Every query needs three things: the keyword SELECT, a list of columns you want to see, and the keyword FROM. Think of SELECT as the request, the column list as your shopping list, and FROM as the aisle where the database finds what you asked for.
Building Your First Query
SELECT
A query always starts with SELECT. It tells the database to return data. Everything listed after SELECT describes which pieces of that data you want to see.
Columns
After SELECT, list each column you want, separated by commas. The database returns exactly those columns, in the order you listed them.
FROM
FROM names the table to query. Databases contain many tables, so naming the right one tells the database exactly where to look for the data you requested.
Arrange the Query
> Build a query that retrieves the product column from the orders table.
Arrange each line of the query in order:
Every SQL query starts with SELECT and ends with the table name after FROM. This ordering is fixed: SELECT declares what data you want, and FROM declares where to find it.
When selecting multiple columns, list each name after SELECT separated by commas: SELECT name, age FROM users. The database returns only the columns you listed, in the order you listed them.
Check Your Understanding
> Complete this query to retrieve user names and ages from the users table.
name, age users
The column list after SELECT is your contract with the database: you are saying exactly which pieces of information matter for this particular question.
Writing SELECT and FROM in uppercase is a convention that makes SQL easier to scan, separating the SQL keywords from the table and column names you supply.
Selecting all columns (*)
Pull complete datasets with one keyword
If you want to see every column in a table, you can use the * symbol instead of listing each column. This is handy when you are exploring a new table.
When to Use *
Knowing when to use SELECT * versus named columns helps you write efficient, readable queries.
Choosing the Right Columns
In practice, the columns you select depend on the question you're trying to answer. A marketing team asking "who are our customers?" needs name and country. A finance team asking "what do things cost?" needs product_name and price. The same database can answer very different questions depending on which columns you choose.
> Complete this query to pull just the product names and prices from inventory.
SELECT , FROM products
In production systems, SELECT * can cause pipelines to break if a new column is added to a table, because downstream code may not expect it. Named columns are more robust.
AS aliases for columns
Rename columns for clearer results
SQL supports two types of aliases using the AS keyword. Column aliases let you rename columns in your results, making the output more readable. Table aliases create shorthand names for tables, which is helpful when working with long table names or multiple tables.
Practical Aliasing
Practice: Column Aliases
> Complete this query to select the email column, renaming it to contact_email.
SELECT email FROM users
Table aliases are used most often when writing JOIN queries, where two tables may have columns with the same name and the alias helps clarify which table each column comes from.
Expressions in SELECT
Calculate new values inside your query
Common Operations
Practice: Expressions
> Complete this query to calculate the total cost for each order line.
SELECT quantity AS total_cost FROM orders
Adding an AS alias to every expression in your SELECT list ensures the output column has a meaningful name instead of the literal formula text, which makes results easier to read.
- List specific columns in SELECT instead of using * in production
- Use meaningful aliases with AS to clarify calculated columns
- Write SQL keywords in uppercase for readability (SELECT, FROM, AS)
- Don't use SELECT * in production queries because it returns unnecessary data
- Don't use spaces or special characters in column aliases without quotes
- Don't forget that FROM is processed before SELECT by the database
- Don't rely on column order; always reference columns by name
> You are a data analyst at Shopify supporting a merchant success team that needs a daily snapshot of product listings. The team wants to see product names, prices, and computed margin values pulled from the catalog database.
SELECT and FROM form the foundation of every query, retrieving the product name and price columns from the listings table.* keeps the report focused on merchant-relevant fields and prevents pipeline breakage when new columns are added.AS aliases rename raw database columns like base_cost_usd into readable labels such as cost for the merchant report output.SELECT compute derived values like price - cost AS margin directly in the query without needing a separate spreadsheet step.SELECT (what columns to show) and FROM (which table to use)* after SELECT to retrieve all columns from a tableAS keyword creates aliases to rename columns or tables in your resultsSELECT can calculate new values like totals or differencesFROM first to locate the table, then SELECT to choose columns* makes queries faster and results easier to read in productionQuery Structure: Beginner
Your first SQL query starts here
Your first SQL query — demystified
- Category
- SQL
- Difficulty
- beginner
- Duration
- 9 minutes
- Challenges
- 0 hands-on challenges
Topics covered: Tables, rows, and columns, SELECT and FROM basics, Selecting all columns (*), AS aliases for columns, Expressions in SELECT
Lesson Sections
- Tables, rows, and columns
Inside each table in a database, information is organized into rows and columns. A row is a single record, such as one person, one order, or one product. A column is a type of information stored for every record, such as a name, a price, or a date. A cell is a single value, such as the name 'John' or the date 2025-10-12. Together, the rows and columns form a grid of cells much like a spreadsheet. You can look across a row to see all the details for one record, or down a column to see that type o
- SELECT and FROM basics (concepts: sqlSelectFrom)
Every SQL query follows a predictable structure that tells the database what data you want and where to find it. Building Your First Query Understanding the role of each keyword helps you construct queries that retrieve exactly the data you need. SELECT Columns FROM Arrange the Query Check Your Understanding Selecting only the columns you need, rather than all columns, reduces the amount of data the database must read and transfer, which makes queries faster on large tables.
- Selecting all columns (*)
The asterisk symbol provides a quick way to retrieve all columns without typing each name individually. When to Use * Choosing the Right Columns Now try selecting different columns from a product inventory table. Requesting only the columns relevant to your question means analysts reading your query can immediately understand what data you care about without scrolling through irrelevant output. The ability to select any combination of columns from a table is one of the core reasons SQL is so fle
- AS aliases for columns
Aliases let you create readable, descriptive names for columns and tables without changing the underlying data. When you use an alias, the underlying table and its data remain unchanged. The alias only affects how the data is labeled in your query and results. Toggle between the examples below to see each type. Practical Aliasing Production databases often have column names like usr_cre_dt or prc_usd_base that save keystrokes when engineers build the schema but confuse everyone reading queries l
- Expressions in SELECT
Expressions transform data on the fly, letting you compute totals, differences, and other derived values directly in your query. An expression is any combination of values, operators, and functions that the database evaluates to produce a result. For example, "price + tax" is an expression that adds two column values together. SQL can calculate new values as part of the results using expressions. Common Operations SQL supports standard arithmetic operators that let you perform calculations direc