mysql - Excluding record NON unique Field Data -
this similar a previous post made recently: bit different. if looks familiar: please excuse learning curve trying understand : "well case , case....."
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 want totally suppress records don't have totally unique phone numbers.
i need suppress (1) jim , (2) tom , return
5 oscar 622 first 5125551212 3 steve 653 pine 5125901977
select id, name, address, phone clients state in ( 'mo', 'la', 'ct' ) , foo > 40 , phone not in ( select phone clients group phone having count(*) > 1 ) order foo
Comments
Post a Comment