This website uses cookies

Read our Privacy policy and Terms of use for more information.

You've written SELECT * at least a few times by now. It works, but it returns every column when you might only need two.

SELECT does more than pick columns. It transforms your output.

-- Rename columns
SELECT name AS customer_name, email AS contact
FROM customers

-- Compute expressions
SELECT name, 2026 - YEAR(signup_date) AS years_as_customer
FROM customers

-- Transform text
SELECT name, UPPER(city) AS city_uppercase
FROM customers

This maps to Python's list comprehensions:

[{'customer_name': c['name'], 'contact': c['email']} for c in customers]

One gotcha: if any value in your expression is NULL, the whole result becomes NULL. We'll dig into why later in the series.

This week's post covers aliases, expressions, and DISTINCT (plus why DISTINCT can hide problems in your queries).

Next week: ORDER BY, because rows come back in no guaranteed order.

-Jamal

Keep Reading