CadencePlus Solutions

Aliases and DISTINCT

Give results names people can understand, and remove repeated combinations only when the question calls for it.

Column aliases

AS gives a result column a label. It does not rename the stored column. SELECT customer_name AS name produces an output called name.

Table aliases

FROM customers AS c gives the table a short name within this query. Use c.country to identify a column’s source, especially when joined tables share names.

Distinct combinations

DISTINCT applies to the complete selected row. SELECT DISTINCT country returns each country once. Adding city can produce several rows for the same country because the combinations differ.

Duplicates need a reason

Repeated values are not automatically bad data. Different orders can belong to the same customer. Investigate the grain before using DISTINCT to hide repeated rows.