Some questions want each value only once. “Which cities do our customers live in?” doesn't need Cluj twice just because two customers live there. Put DISTINCT right after SELECT, and the database removes repeated rows from the answer.
DISTINCT changes only the answer, not the table: every customer is still there. It doesn't sort either, so add ORDER BY when you want the values in order.
Here is the idea on another table. Each order has a customer_id, and one customer can place many orders. This query lists the id of each customer who ordered, once, however many orders they placed.
var query = "SELECT DISTINCT customer_id " +
"FROM orders "
Your query must print the customers' cities, each once, from A to Z:
city Berlin Cluj Madrid Rome (4 rows)
Your task: write a query that lists the city of the shop's customers from the customers table, each city once, sorted from A to Z.
Assignment
Follow the Coding Tutorial to build the query one clause per line: SELECT DISTINCT and the column, then FROM, then ORDER BY.
HintDISTINCT goes between SELECT and the column's name. End each string with a space inside the quotes, so the words don't run together when Go joins the pieces. Every piece but the last ends with +.
Free plan: 30 tutor messages. PRO is unlimited.
