
Here's a preview from my zine, Become a SELECT Star!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
SELECT is where you pick the final columns that appear in the table the query outputs. Here’s the syntax:
SELECT expression_l [AS alias],
expression_2 [AS alias2],
FROM ...
Some useful things YOU can do in a SELECT :
- Combine many columns with SQL expressions
A few examples:
CONCAT (first_name, ' ', last_name) DATE_TRUNC('month', created)
(This is PostgreSQL syntax for rounding date, other SQL dialects have different syntax)
- Alias an expression with AS
first_name || ' ' || last_name AS full_name
is a mouthful! If you alias an expression with AS, you can use the alias elsewhere in the query to refer to that expression.
(|| is a concatenation operation)
SELECT first_name || ' ' || last_name AS full_name
FROM people
ORDER BY full_name desc
(full_name
refers to first_name || ' ' || last_name
)
- Select columns with SELECT *
When I’m starting to figure out a query, I’ll often write something like
SELECT * FROM some _ table LIMIT 10
just to quickly see what the columns in the table look like.
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!