Question : Why does Update bring a lot of Null in the traget table ?

I have an order master table (ormast) with 3,000 records and the primary key is ord_no. I also have a small table (new_rate) with about 100 records of new rate which will be used to update the ormast table. Here is the command:
UPDATE ormast SET frate=(SELECT rate FROM new_rate WHERE ormast.ord_no=new_rate.ord_no)
The result is unexpected -- I got the 100 orders updated with the new rate BUT all other 2,900 orders' frate column are with NULL value. What could be wrong? Did I miss anything?

Answer : Why does Update bring a lot of Null in the traget table ?

either:

UPDATE ormast SET frate=(SELECT rate FROM new_rate WHERE ormast.ord_no=new_rate.ord_no)
  AND EXISTS(SELECT rate FROM new_rate WHERE ormast.ord_no=new_rate.ord_no)

OR:

UPDATE t
  SET frate= n.rate
FROM ormast  t
 JOIN new_rate n
   ON t.ord_no= n.ord_no
 AND n.rate IS NOT NULL
Random Solutions  
 
programming4us programming4us