Section 1 · Lesson 1

Your first query: SELECT and FROM

Read columns from a table, rename them, and preview data safely with LIMIT.

20 min 3 practice tasks Free preview
SQL SELECT Tutorial by Socratica on YouTube

Every SQL query answers a question about data that lives in tables: rows of records, each with the same named columns. In this course you’ll work with a fictional ad-tech company’s database: advertisers run campaigns, campaigns generate daily performance stats, and customers place orders.

The shape of a query

SELECT name, channel      -- which columns you want
FROM campaigns;           -- which table they come from
  • SELECT lists the columns to return, separated by commas. SELECT * returns all of them.
  • FROM names the table.
  • The semicolon ends the statement. SQL keywords aren’t case-sensitive, but writing them in UPPERCASE makes queries easier to scan.

Renaming columns with AS

Column names in the result can be changed with an alias. This doesn’t modify the table; it only labels the output, which matters when you share results or build reports.

SELECT name AS campaign_name, daily_budget AS budget_usd
FROM campaigns;

Previewing with LIMIT

Real tables can have millions of rows. Before running anything heavy, peek at a few rows:

SELECT * FROM daily_stats LIMIT 10;

Without an ORDER BY (next lessons), the database returns rows in whatever order is cheapest, so LIMIT alone gives you a sample, not the “top” rows.

Explore the dataset

Use the Tables panel in the sandbox to see every table and its columns. Try these in the sandbox before the tasks:

SELECT * FROM campaigns LIMIT 5;
SELECT first_name, last_name, country FROM customers LIMIT 5;

Tip: Selecting only the columns you need is faster and makes results easier to read. Professionals avoid SELECT * in production queries.

Practice

Write your answer, press Run to see results and Check answer to grade it. Shortcuts: Ctrl/⌘ + Enter run, Shift + Enter check.

1

Meet the advertisers

Return every column for every row in the advertisers table.

Need a hint?
  1. * means all columns.
  2. The pattern is SELECT ... FROM table_name;
SQL · SQLite
-- Write your query below
Tables in this database
advertisers (12 rows)
id, name, industry, country
campaigns (40 rows)
id, advertiser_id, name, channel, objective, start_date, end_date, daily_budget, status
daily_stats (1,561 rows)
campaign_id, date, impressions, clicks, spend, conversions, revenue
customers (300 rows)
id, first_name, last_name, email, country, segment, age_group, signup_date
orders (900 rows)
id, customer_id, campaign_id, order_date, amount, status
ab_test (4,000 rows)
user_id, variant, device, time_on_page_sec, converted, revenue
2

Pick specific columns

List each campaign's name, channel and daily_budget, in that column order.

Need a hint?
  1. Separate column names with commas.
SQL · SQLite
SELECT name
FROM campaigns;
Tables in this database
advertisers (12 rows)
id, name, industry, country
campaigns (40 rows)
id, advertiser_id, name, channel, objective, start_date, end_date, daily_budget, status
daily_stats (1,561 rows)
campaign_id, date, impressions, clicks, spend, conversions, revenue
customers (300 rows)
id, first_name, last_name, email, country, segment, age_group, signup_date
orders (900 rows)
id, customer_id, campaign_id, order_date, amount, status
ab_test (4,000 rows)
user_id, variant, device, time_on_page_sec, converted, revenue
3

Rename and preview

Show the first 5 rows of daily_stats with two columns: date, and spend renamed to spend_usd. Keep the table's natural order (no sorting needed).

Need a hint?
  1. AS gives a column a new name in the result.
  2. LIMIT 5 returns at most five rows.
SQL · SQLite
SELECT date, spend
FROM daily_stats;
Tables in this database
advertisers (12 rows)
id, name, industry, country
campaigns (40 rows)
id, advertiser_id, name, channel, objective, start_date, end_date, daily_budget, status
daily_stats (1,561 rows)
campaign_id, date, impressions, clicks, spend, conversions, revenue
customers (300 rows)
id, first_name, last_name, email, country, segment, age_group, signup_date
orders (900 rows)
id, customer_id, campaign_id, order_date, amount, status
ab_test (4,000 rows)
user_id, variant, device, time_on_page_sec, converted, revenue