I assume the first table is table1, the second table is table2. As a result, it displays the list of sms to be sent, eliminating parent and class coincidences
select result.sms,
result.c_id,
result.parent_id,
result.phone_num
from
(select stt.*,
ROW_NUMBER() over (partition by stt.c_id, stt.parent_id order by stt.c_id) as sms
from
(select table1.stu_id,
table1.stu_name,
dense_rank() over(order by parent_id) as parent_id,
dense_rank() over(order by c_id) as c_id,
table2.phone_num
from Table1 inner join Table2 on Table1.parent_id = Table2.par_id) as STT) as result
where result.sms = 1