By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t1(c1 date, c2 varchar(10),c3 int)
insert into t1 values
(date('10/6/19'),'A',1),
(date('12/6/19'),'B',1),
(date('13/6/19'),'A',2),
(date('09/6/19'),'A',3),
(date('03/6/19'),'B',1),
(date('04/6/19'),'B',2),
(date('12/6/19'),'B',4),
(date('03/6/19'),'A',5),
(date('06/6/19'),'B',3)
select * from t1 a
where c1 =(select max(c1) from t1 b where a.c3=b.c3 )
and c2='B'
c1 | c2 | c3 |
---|---|---|
2012-06-19 | B | 1 |
2012-06-19 | B | 4 |
create table t2(idA int, idB int)
insert into t2 values(23,6),(23,7),
(5,5),(4,4),(3,3), (2,2),
(1,1),(1,8)
select * from t2 a
where exists (select 1 from t2 b where a.idA=b.idA group by b.idA having count(*)>1)
idA | idB |
---|---|
23 | 6 |
23 | 7 |
1 | 1 |
1 | 8 |