Reputation: 1549
I have a table called 'customers', and I have to sort it first by country and by city, which I have successfully done.
Using this code:
SELECT *
FROM customers
ORDER BY Country, City
But from the output that I have, how do I print only the list of cities?
My table has several attributes or columns such as companyName, contactName, etc...
Thank you very much.
Upvotes: 3
Views: 29902
Reputation: 4171
Enter the specific column names instead of * , which indicates all the column names.
e.g.
SELECT City FROM customers
ORDER BY Country, City
Upvotes: 1
Reputation: 3324
The SELECT criteria determines the columns displayed, while the WHERE criteria determines what rows are displayed :)
In your case it would be: SELECT City FROM customers ORDER BY Country, City
The * represents a 'wildcard' which in this case means display all.
If you wished to display both Country and city it would be:SELECT City, Country FROM customers ORDER BY Country, City
The order of the columns is determined by which order you write them in the SELECT statement.
Upvotes: 1
Reputation: 204756
SELECT City FROM customers ORDER BY Country, City
Replace *
with the columns you want to show - City
in your case.
Upvotes: 7