jeudi 23 juillet 2015

MySQL Java getting objects by a distinct field

I need to return java objects from my database by distinct field. In my database I have Country, State, City. Now I have 2 records where they have the same data in the fields, but I only want to return distinct states in a country.

To clarify - I have two records with the same country and state. I only want to return one state instead of Washington twice for example. However, I need the object as opposed to returning the string of washington.

My query:

SELECT DISTINCT r FROM Roster r where r.state = :state AND r.country = :country

What is happening is it will return all the duplicates because the objects are not distinct, where I just want one of each?

I apologise if I was not very clear.

Any help would be greatly appreciated!

edit: I need the objects because I am using them to populate a results table.

Aucun commentaire:

Enregistrer un commentaire