mysql - Getting Records With Unique Phone Number -
i have nice little query works. queries single "clients" table
here table: sqlfiddle here: http://sqlfiddle.com/#!2/1fcea
create table `clients` ( `id` int not null auto_increment , `name` varchar(45) null , `address` varchar(45) null , `state` varchar(45) null , `foo` varchar(45) null , `phone` varchar(45) null , primary key (`id`) ); insert into`clients` (`name`, `address`, `state`, `foo`, `phone`) values ('jim', '123 main', 'mo', '876', '2038221661'); insert into`clients` (`name`, `address`, `state`, `foo`, `phone`) values ('tom ', '234 elm', 'mo', '433', '2038221661'); insert into`clients` (`name`, `address`, `state`, `foo`, `phone`) values ('steve', '653 pine', 'ct', '863', '5125901977'); insert into`clients` (`name`, `address`, `state`, `foo`, `phone`) values ('dave', '654 oak', 'nv', '872', '8769085435'); insert into`clients` (`name`, `address`, `state`, `foo`, `phone`) values ('oscar', '622 first ', 'la', '625', '5125551212');
here query
select id, name, address, phone clients state in ( 'mo', 'la', 'ct' ) , foo > 40 order foo
it returns:
2 tom 234 elm 2038221661 5 oscar 622 first 5125551212 3 steve 653 pine 5125901977 1 jim 123 main 2038221661
i dont want want our customer service people calling place more once. need return distinct phone numbers.
i need suppress (1) jim , return
2 tom 234 elm 2038221661 5 oscar 622 first 5125551212 3 steve 653 pine 5125901977
select id, name, address, phone clients state in ( 'mo', 'la', 'ct' ) , foo > 40 , id in ( select min(id) clients group phone ) order foo
Comments
Post a Comment