How to implement if (t1.ID=t2.ID) returned nothing do the stuff
From what I understand you want a LEFT JOIN (it really helps if definitions of tables, sample data and expected results is included in the question):

SELECT t2.id, coalesce(t1.name, '---') as name
     , CASE WHEN t2.id = t1.id THEN 'EQUAL' ELSE 'NOT EQUAL' END 
FROM t2
LEFT JOIN t1
    ON t2.id = t1.id


coalesce returns the leftmost column that is not null, in this case t1.name if it's not null and --- otherwise. If you want to avoid a join (not sure why) you can use a sub select:

SELECT t2.id, coalesce((SELECT t1.name
                        FROM t1
                        WHERE t2.id = t1.id), '---') as name
FROM t2;