user1060551
user1060551

Reputation: 431

updating table with data from different source

I am trying to do the following:

update mytable 
set fullname = anothersource.firstname ||' '|| anothersource.lastname
where
userid = anothersource.userid
;

I am having errors which I am not pasting because it make not sense since I simplified the example, however, is there a special way of handling updates with information from different sources? I believe that may be where problem lives.

Thanks

Upvotes: 0

Views: 48

Answers (2)

ajmalmhd04
ajmalmhd04

Reputation: 2602

UPDATE mytable
SET  fullname =
     (SELECT firstname FROM anothersource WHERE user_id = user_id)
     ||' '||
     (SELECT lastname FROM anothersource1 WHERE user_id = user_id)
WHERE mytable_id = id;

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270583

You need a subquery for Oracle:

update mytable 
    set fullname = (select anothersource.firstname ||' '|| anothersource.lastname
                    from anothersource
                    where mytable.userid = anothersource.userid
                   );

If there is the danger that the subquery might return more than one row, then use an aggregation (such as min() or where rownum = 1).

Upvotes: 1

Related Questions