4. Query anatomy: SELECT and FROM

Without further ado let’s write our very first query:

SELECT *
FROM users

This query could be translated into something like “Give me all columns from a table named users”.

SELECT is a keyword that tells SQL what columns you want to get. After SELECT we can use a wildcard (*) to get all available columns. Alternatively, we can specify columns we’d like to have like so:

SELECT
  email,
  signup_date,
  created_at
FROM users

As you can see we just need to separate column names with a comma. Btw, this query ☝ will list all users’ emails with their signup dates (date column) and signup timestamps (datetime column). It’s a convention to have timestamps named like something_atcreated_at (when the record was created), updated_at, published_at, etc.

FROM is another keyword that tells SQL where we want to get the data from. It should be followed up with a name.

For example, this query will get all records from a books table:

SELECT *
FROM books

Go to the Playground and try out these queries 🚀

💡 The Playground supports keyboard shortcuts for running queries: CMD + Enter on Mac and CTRL + Enter on Windows.

Anatoli Makarevich, author of SQL Habit About SQL Habit

Hi, it’s Anatoli, the author of SQL Habit. 👋

SQL Habit is a course (or, as some of the students say, “business simulator”). It’s based on a story of a fictional startup called Bindle. You’ll play a role of their Data Analyst 📊 and solve real-life challenges from Business, Marketing, and Product Management.

SQL Habit course is made of bite-sized lessons (you’re looking at one atm) and exercises. They always have a real-life setting and detailed explanations. You can immediately apply everything you’ve learned at work. 🚀

“well worth the money”

Fluent in SQL in a month

Master Data Analysis with SQL with real life examples from Product Management, Marketing, Finance and more.
-- Type your query here, for example this one -- lists all records from users table: SELECT * FROM users
LIMIT 500
Loading chart... ⏳