BEGIN TRANSACTION;
drop table tuser;
drop table tuser_info;
CREATE TABLE tuser
(`id` int, `name` varchar(255));
INSERT INTO tuser
(`id`, `name`)
VALUES
(1, 'Vasja'),
(2, 'Petja'),
(3, 'Kolja'),
(4, 'Dima')
;
CREATE TABLE tuser_info
(`id` int, `user_id` int, `some_id` int);
INSERT INTO tuser_info
(`id`, `user_id`, `some_id`)
VALUES
(1, 1,1),
(2, 2,3),
(3, 2,1),
(5, 2,2),
(4, 3,1)
;
COMMIT;
select tu.name
from tuser tu
join tuser_info ti
on (tu.id = ti.user_id)
where ti.some_id=1
and exists (select 1 from tuser_info ti2 where ti2.some_id=2 and ti2.user_id=ti.user_id );