We help IT Professionals succeed at work.

SQL Update - very simple

Medium Priority
353 Views
Last Modified: 2013-12-19
just can't remember - - need to update a a field on every row to another field on the same row - - all records; table has 3 keys - - something like this:
update ps_term_tbl a set a.ssr_trmac_last_dt = a.term_begin_dt where
(select a.institution, a.acad_career, a.strm, a.term_begin_dt, a.ssr_trmac_last_dt,
  b.institution, b.acad_career, b.strm from ps_term_tbl a, ps_term_tbl b where
   a.institution = b.institution and a.acad_career = b.acad_career and a.strm = b.strm)
Comment
Watch Question

AneeshDatabase Consultant
CERTIFIED EXPERT
Top Expert 2009

Commented:
update ps_term_tbl  
set  ssr_trmac_last_dt = term_begin_dt where
Database Consultant
CERTIFIED EXPERT
Top Expert 2009
Commented:
update ps_term_tbl  
set  ssr_trmac_last_dt = term_begin_dt

Author

Commented:
duh - thanks

Commented:
<<need to update a a field on every row to another field on the same row - - all records;>>
UPDATE ps_term_tbl a
   SET a.ssr_trmac_last_dt = a.term_begin_dt;
/*
 WHERE (SELECT a.institution, a.acad_career, a.strm, a.term_begin_dt,
               a.ssr_trmac_last_dt, b.institution, b.acad_career, b.strm
          FROM ps_term_tbl a, ps_term_tbl b
         WHERE a.institution = b.institution
           AND a.acad_career = b.acad_career
           AND a.strm = b.strm)
*/

Your update statement is right, only you are using WHERE clause extra
UPDATE ps_term_tbl a
   SET a.ssr_trmac_last_dt = a.term_begin_dt;

Open in new window