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.
SELECT City FROM customers ORDER BY Country, City
Replace * with the columns you want to show - Cityin your case.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With