My table is like this:
CREATE TABLE candidate_tbl (
`name` VARCHAR(1),
`degree` VARCHAR(41),
`doneMasters` VARCHAR(6)
);
INSERT INTO candidate_tbl
(`name`, `degree`, `doneMasters`)
VALUES
('A', 'MBA', 'true'),
('A', 'MS', 'false'),
('B', 'MBA', 'true'),
('B', 'MS', 'true'),
('C', 'MBA', 'false'),
('C', 'MS', 'false'),
('D', 'MBA', 'false'),
('D', 'MS','true'),
('E', 'MBA', 'false'),
('E', 'MS', 'false'),
('F', 'MBA', 'false'),
('F', 'MS', 'true'),
('G', 'MBA', 'false'),
('G', 'MS', 'false'),
('H', 'MS', 'true'),
('H', 'MS', 'true');
I want the list of candidates who neither has MS nor MBA, which is C,E and G
I tried these 4 ways, Fiddle given here
Method-1
SELECT name,count(*) FROM candidate_tbl
WHERE doneMasters = 'false'
AND doneMasters = 'false'
GROUP BY name
HAVING count(*) = 2;
Method-2
SELECT DISTINCT name FROM candidate_tbl ct1 WHERE NOT EXISTS
(
SELECT name FROM candidate_tbl ct2 WHERE ct1.name = ct2.name and doneMasters = 'true'
);
Method-3
SELECT name FROM (SELECT name,group_concat(doneMasters) as dmf FROM candidate_tbl
GROUP BY name) dd
WHERE dmf = 'false,false';
Method-4
SELECT name FROM (SELECT name, group_concat(doneMasters) as dmf FROM candidate_tbl
GROUP BY name) dd
WHERE dmf = 'false,false';
I want to know which is the best solution in terms of performance and accuracy, or other alternate solutions.