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

Daily Life
Interviews

Read and navigate any database table

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.
namecountryage
Maya SantosBrazil28
Emma BrooksUnited States34
Ravi MenonIndia26
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 of information for many records.

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

Daily Life
Interviews

Pull specific columns from any table

Every SQL query follows a predictable structure that tells the database what data you want and where to find it.

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.

1SELECT
2 name,
3 country
4FROM users
TIP
You are telling the database "Show me the name and country of each user from the users table." The database returns a smaller result with only the requested columns.

Building Your First Query

Understanding the role of each keyword helps you construct queries that retrieve exactly the data you need.
//

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

Parsons Problem

> Build a query that retrieves the product column from the orders table.

Arrange each line of the query in order:

1
2
3
4

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
SELECT
country
age
FROM
users
name
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.

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 (*)

Daily Life
Interviews

Pull complete datasets with one keyword

The asterisk symbol provides a quick way to retrieve all columns without typing each name individually.

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.

1SELECT
2 *
3FROM users
Result
namecountryage
Maya SantosBrazil28
Emma BrooksUnited States34
Ravi MenonIndia26
TIP
You are telling the database "Show me every column in the users table." Use this to get a quick overview of what data is available before writing more targeted queries.

When to Use *

Knowing when to use SELECT * versus named columns helps you write efficient, readable queries.

SELECT * is great for exploring a new table, but returns every column. On large tables with many columns, this can be slow and return data you do not need.
1SELECT
2 *
3FROM users

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.

Now try selecting different columns from a product inventory table.

> Complete this query to pull just the product names and prices from inventory.

SELECT
  ___,
  ___
FROM products
price
quantity
product_name
category
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.

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.

The ability to select any combination of columns from a table is one of the core reasons SQL is so flexible for answering a wide variety of business questions from the same dataset.

AS aliases for columns

Daily Life
Interviews

Rename columns for clearer results

Aliases let you create readable, descriptive names for columns and tables without changing the underlying data.

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.

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.
Column aliases rename columns in your results. Here, name AS full_name changes the output label from "name" to "full_name". The underlying table is untouched. Only the label shown to you changes.
1SELECT
2 name AS full_name,
3 country
4FROM users

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 later. Aliasing them to created_at or base_price costs one extra word per column and turns your output into something any teammate can read at a glance without consulting the data dictionary.

Practice: Column Aliases

> Complete this query to select the email column, renaming it to contact_email.

SELECT
  email ___ ___
FROM users
AS
FROM
user_email
contact_email
Column aliases are especially valuable in reports and dashboards where the raw column names from the database, like usr_email_addr, would confuse non-technical readers.
Because aliases only exist in the output of a query, you can safely rename the same column to different things in different queries without touching the underlying table.

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

Daily Life
Interviews

Calculate new values inside your query

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.
1SELECT
2 price,
3 quantity,
4 price + tax AS total_price
5FROM orders
TIP
This query tells the database "Show me the price, the quantity, and a calculated column called total_price that adds price and tax together, for every row in the orders table."

Common Operations

SQL supports standard arithmetic operators that let you perform calculations directly within your queries.
The + operator adds two column values together. Here it combines price and tax into a single total cost per row.
1SELECT
2 price + tax AS total_cost
3FROM orders

Practice: Expressions

Put your expression skills to work by calculating a total cost from quantity and unit price.

> Complete this query to calculate the total cost for each order line.

SELECT
  quantity ___ ___ AS total_cost
FROM orders
quantity
*
unit_price
+
Expressions let you compute answers directly in the database rather than pulling raw numbers into a spreadsheet and calculating there, which is both faster and more reliable.

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.

Do
  • 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
  • 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
PUTTING IT ALL TOGETHER

> 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.
Selecting specific named columns instead of * 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.
Expressions in SELECT compute derived values like price - cost AS margin directly in the query without needing a separate spreadsheet step.
KEY TAKEAWAYS
A database stores information in tables, with rows representing records and columns representing attributes
SQL (Structured Query Language) is the human-readable language used to communicate with databases
Every SQL query needs SELECT (what columns to show) and FROM (which table to use)
Use * after SELECT to retrieve all columns from a table
The AS keyword creates aliases to rename columns or tables in your results
Expressions in SELECT can calculate new values like totals or differences
The database processes FROM first to locate the table, then SELECT to choose columns
Selecting specific columns instead of * makes queries faster and results easier to read in production

Query 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

  1. 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

  2. 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.

  3. 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

  4. 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

  5. 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