MySQL Forums
Forum List  »  InnoDB

Help with Select
Posted by: aeron glemann
Date: April 06, 2005 09:16AM

Hi-

I would like to know if it's possible to return unique values for a field that has NOT been uniquely indexed. For example, my database has a field for Countries, a field for Political Sub-divisions (states, provinces, territories, etc..) and a field for Cities. It would follow that the value for Countries - while unique since no two countries share the same name - is duplicated many times (there are only a couple hundred Countries in the world but hundreds of thousands of Cities). The value for the Political Sub-divisions is not unique - since different Countries may share provinces or territory names with other Countries - however the values themselves are unique to each Country. Likewise the Cities are not unique either EXCEPT to each Sub-division of each Country.

If you've followed me this far, I would like to know if it's possible to query the database to return just the names of the Political Sub-divisions of a Country. Obviously a Country could have thousands of Cities, but much fewer Sub-divisions. If I select it as see:

SELECT sub-division FROM db.cities WHERE country IS some_country

It's going to return the Sub-divisions for each city entry - which may only be 10 Sub-Divisions but duplicated hundreds of times for each city. SO - is it possible to return just one instance of each Sub-division. I didn't get this from the docs, but maybe someone here is cleverer than I am.

If anything isn't clear, please let me know if I could help illustrate it further. Thanks a LOT.

Options: ReplyQuote


Subject
Views
Written By
Posted
Help with Select
2809
April 06, 2005 09:16AM
2160
April 22, 2005 07:37AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.