https://www.youtube.com/watch?v=WumXyCh8U4g&list=PLavw5C92dz9Hxz0YhttDniNgKejQlPoAn&index=26
drop table if exists tokens;
create table tokens
(
token_num int,
customer varchar(20)
);
insert into tokens values(1, 'Maryam');
insert into tokens values(2, 'Rocky');
insert into tokens values(3, 'John');
insert into tokens values(3, 'John');
insert into tokens values(2, 'Arya');
insert into tokens values(1, 'Pascal');
insert into tokens values(9, 'Kate');
insert into tokens values(9, 'Ibrahim');
insert into tokens values(8, 'Lilly');
insert into tokens values(8, 'Lilly');
insert into tokens values(5, 'Shane');
select * from tokens;
-- Approach 1
SELECT MIN(token_num) AS Token_Num FROM (
select distinct t1.token_num
FROM tokens t1
LEFT JOIN tokens t2 ON t1.token_num = t2.token_num AND t1.customer != t2.customer
WHERE t2.customer IS NULL
) x
-- Approach 2
SELECT token_num FROM (
SELECT DISTINCT *
FROM tokens) x
GROUP BY token_num
HAVING COUNT(token_num) = 1
ORDER BY token_num
LIMIT 1