MySQL Java getting objects by a distinct field -


i need return java objects database distinct field. in database have country, state, city. have 2 records have same data in fields, want return distinct states in country.

to clarify - have 2 records same country , state. want return 1 state instead of washington twice example. however, need object opposed returning string of washington.

my query:

select distinct r roster r r.state = :state , r.country = :country 

what happening return duplicates because objects not distinct, want 1 of each?

i apologise if not clear.

any appreciated!

edit: need objects because using them populate results table.

edit2: create table:

create table `roster` (   `id` int(10) unsigned not null auto_increment,   `country` varchar(45) not null,   `state` varchar(45) not null,   `city` varchar(45) default null,   `clientname` varchar(45) not null,   `tdomain` varchar(45) not null,   `tsubdomain` varchar(45) default null,   `treferenceid` varchar(45) default null,   `startdate` date default null,   `enddate` date default null,   `starttime` time default null,   `endtime` time default null,   `designation` varchar(45) default null,   `role` varchar(45) default null,   `name` varchar(45) not null,   `surname` varchar(45) not null,   `mobilenumber` varchar(45) default null,   `officenumber` varchar(45) default null,   `email` varchar(45) default null,   `availability` tinyint(1) not null,   `comments` varchar(45) default null,   primary key (`id`) ) engine=innodb auto_increment=7 default charset=latin1 

everything treferenceid common. rest going unique. toying idea of splitting table two. involve quite hefty rewrite.

i wouldn't know jpa if fell on head. fumble after this:

select distinct r.country,r.state,r.city  roster r  r.state = :state , r.country = :country 

edit:

ok wrong object :>

how about

create table roster (     id int auto_increment primary key,     country varchar(100) not null,     state varchar(100) not null,     city varchar(100) not null );  insert roster (country,state,city) values ('usa','kentucky','louisville'); insert roster (country,state,city) values ('usa','illinois','chicago'); insert roster (country,state,city) values ('usa','kentucky','louisville'); insert roster (country,state,city) values ('usa','kentucky','blah_blah'); 

and strings use

select * roster r join  (select min(id) cheatid roster country='usa' , state='kentucky') inr on inr.cheatid=r.id  +----+---------+----------+------------+---------+ | id | country | state    | city       | cheatid | +----+---------+----------+------------+---------+ |  1 | usa     | kentucky | louisville |       1 | +----+---------+----------+------------+---------+ 1 row in set (0.00 sec) 

and objects use:

select r roster r join  (select min(id) cheatid roster country=:country , state=:state) inr on inr.cheatid=r.id 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -