Update query Oracle

I have table TB1 which has the following cols:

ID        |    date  
1         |    12-JUL-10
2         |    12-JUL-10
3         |    12-JUL-10
4         |    12-JUL-10
10000     |    12-JUL-10


ID        |    date  
1         |    12-JAN-09
2         |    12-JUL-09
3         |    12-JUL-09
4         |    12-JUL-08
5800      |    12-JUL-08

How to update the table2's date which has similar ID as table1.

Thanks :)


In general

   UPDATE table2 t2
       SET date_col = (SELECT t1.date_col
                         FROM table1 t1
                        WHERE t1.id = t2.id)
        SELECT 1
          FROM table1 t1
         WHERE t1.id = t2.id )

If you can be guaranteed that every ID in table2 exists in table1 (or if you want the date_col set to NULL if there is no match), you can eliminate the WHERE EXISTS. But generally you only want to do an update if there is a matching record.

Need Your Help

Difference between a method and a function

oop function methods scripting terminology

Can someone provide a simple explanation of methods vs. functions?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.