Projections and DISTINCT

Projections, Aliases, and DISTINCT

The select list is the projection: the columns and expressions the result carries. AS names an output column (backticks allow spaces); a table alias such as products AS p shortens references and is compulsory when a table appears twice (Self and Multi-Table Joins).

A missing comma and a computed aliasSQL
SELECT sku title, price * 0.9 AS `member price` FROM products WHERE category_id = 3;
Output
+-----------+--------------+
| title     | member price |
+-----------+--------------+
| BK-SQL-01 |       40.050 |
| BK-SQL-02 |       26.100 |
+-----------+--------------+
2 rows in set (0.000 sec)

The "title" column holds SKUs: AS is optional, so the missing comma made sku title an alias without any error. Always write AS. The third decimal comes from DECIMAL(8,2) times 0.9; round money with ROUND(..., 2).

DISTINCT removes duplicate rows across the whole projection and treats NULLs as equal: SELECT DISTINCT parent_id FROM categories returns two rows, NULL and 1. COUNT(DISTINCT country) counts 7 countries for 8 customers. A DISTINCT that hides join duplicates usually masks a fan-out (Self and Multi-Table Joins).