How to implement if (t1.ID=t2.ID) returned nothing do the stuff I have two tables one table1 containing ID, NAME another table2 is only ID.

I want to have all IDs in table2 and return ID in table2 and NAME in table1 but I also want IDs in table2 which is not exist in table1 and just print ID, - - -. 

How do I implement if (table1.ID=table2.ID) returned nothing do the stuff as well and print ID with null NAME column.
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;