Devression
Devression

Reputation: 457

How to list distinct names of cities in SQL select statement?

I need to find the total number of distinct names of cities being the departure locations for at least one trip. A city is a departure location when it is a departure location of the first leg of a trip.

Here is my code so far:

SELECT DEPARTURE
FROM TRIPLEG
WHERE LEGNUM = 1;

When I test this select statement, the results show all the departure locations (even if a city is mentioned more than once).

How do I make it so that a city name is only displayed once?

Upvotes: 1

Views: 1817

Answers (2)

Tran hao
Tran hao

Reputation: 1

You should use group by

SELECT DEPARTURE
FROM TRIPLEG
WHERE LEGNUM = 1
GROUP BY DEPARTURE;

Upvotes: 0

James A Mohler
James A Mohler

Reputation: 11120

Do you mean something like

SELECT DISTINCT DEPARTURE
FROM TRIPLEG
WHERE LEGNUM = 1;

Upvotes: 1

Related Questions