thử
select t1.name, t1.id as id1,t2.id as id2
from tablename t1, tablename t2
where t1.flag = 0 and t2.id = t1.id+1 and t2.flag = 1 and t1.name = t2.name
thử
select t1.name, t1.id as id1,t2.id as id2
from tablename t1, tablename t2
where t1.flag = 0 and t2.id = t1.id+1 and t2.flag = 1 and t1.name = t2.name