Sql problem/stored procedure

hello,

table 1:
Id, CategoryId, Amount

table 2:
id, CategoryId, Amount

Question:

How Can I used amount from table 2 if exists, if not exists used from table 1 because in table 1 every time exists?

Select case when t2.amount is null then t1.amount else t2.amount end as Amount
from table t1
inner join table t2
on t1.categoryid=t2.categoryid

If all CategoryId's do not exist in table2, change @ahmeds08 query to a LEFT join rather than an INNER join.