By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Create Table table_name(id INT, source INT);
Insert Into table_name Values(1,10),
(1,20),
(1,30),
(2,10),
(2,20),
(2,30),
(3,10),
(3,20);
Records: 8 Duplicates: 0 Warnings: 0
SELECT source, COUNT(DISTINCT id) FROM
table_name
GROUP BY source
HAVING COUNT(DISTINCT id)=(SELECT COUNT(DISTINCT id) FROM table_name)
source | COUNT(DISTINCT id) |
---|---|
10 | 3 |
20 | 3 |
CREATE PROCEDURE getSourceWithAllIds()
BEGIN
SELECT source FROM
table_name
GROUP BY source
HAVING COUNT(DISTINCT id)=(SELECT COUNT(DISTINCT id) FROM table_name);
END
call getSourceWithAllIds();
source |
---|
10 |
20 |