'Trying to update with inner join. 2 tables(employee,contact) Joining w/common element id. Updating cellphone in contact, using fname,lname in employee

I'm (3 days)new to SQL, and this is an assessment for a paid job training program, so I would be very grateful for any help.

The assignment: Update Susan Shepard's cellphone to be 4383991212 using fname and lname in where clause.

So here's all my code for the 2 tables and the update query. Thanks in advance for any help or direction.

CREATE TABLE employee (id int, fname text (255), lname text (255), age int, hiredate date);

INSERT INTO employee (id, fname, lname, age, hiredate)
VALUES ('01', 'Alan', 'Palmer', 32, '2019-12-15');
INSERT INTO employee (id, fname, lname, age, hiredate)
VALUES ('02', 'Susan', 'Shepard', 28, '2015-07-21');
INSERT INTO employee (id, fname, lname, age, hiredate)
VALUES ('03', 'Justin', 'Ward', 43, '2017-08-24');
INSERT INTO employee (id, fname, lname, age, hiredate)
VALUES ('04', 'Alan', 'Smith', 30, '2017-06-22');
INSERT INTO employee (id, fname, lname, age, hiredate)
VALUES ('05', 'James', 'Betternot', 26, '2017-06-22');

CREATE TABLE contact (id int, cellphone text (255), homephone text (255), email text (255));

INSERT INTO contact (id, cellphone, homephone, email)
VALUES ('01', '5121325343', '5125234234', '[email protected]');
INSERT INTO contact (id, cellphone, homephone, email)
VALUES ('02', '5129739834', '5129847873', '[email protected]');
INSERT INTO contact (id, cellphone, homephone, email)
VALUES ('03', '6453898502', '6459872345', '[email protected]');
INSERT INTO contact (id, cellphone, homephone, email)
VALUES ('04', '8763238756', '8763736548', '[email protected]');
INSERT INTO contact (id, cellphone, homephone, email)
VALUES ('05', '8880345966', '8888567987', '[email protected]');

UPDATE contact 
SET c.cellphone ='4383991212' 
FROM contact AS c
INNER JOIN employee AS e 
ON c.id = e.id 
WHERE e.fname = 'Susan' AND e.lname = 'Shepard';

I've also tried this:

UPDATE contact 
SET contact.cellphone ='4383991212' 
FROM contact
INNER JOIN employee 
ON contact.id = employee.id 
WHERE employee.fname = 'Susan' AND employee.lname = 'Shepard';

The error I get is this: SyntaxError: Parse error on line 2: ...one ='4383991212' FROM contact AS c I ----------------------^ Expecting 'EOF', 'COMMA', 'RPAR', 'IN', 'LIKE', 'ARROW', 'DOT', 'CARET', 'EQ', 'WHERE', 'SLASH', 'EXCLAMATION', 'MODULO', 'GT', 'LT', 'GTGT', 'LTLT', 'NOT', 'AND', 'OR', 'PLUS', 'STAR', 'END', 'WHEN', 'ELSE', 'REGEXP', 'TILDA', 'GLOB', 'NOT_LIKE', 'BARBAR', 'MINUS', 'AMPERSAND', 'BAR', 'GE', 'LE', 'EQEQ', 'EQEQEQ', 'NE', 'NEEQEQ', 'NEEQEQEQ', 'BETWEEN', 'NOT_BETWEEN', 'IS', 'DOUBLECOLON', 'OUTPUT', 'GO', 'SEMICOLON', got 'FROM'

sql


Solution 1:[1]

This is the correct syntax for a join in the UPDATE statement (for Postgresql):

UPDATE contact AS c
SET cellphone ='4383991212'
FROM employee AS e 
WHERE c.id = e.id  AND e.fname = 'Susan' AND e.lname = 'Shepard';

See the demo.

Solution 2:[2]

If this is for York Solutions, they check to make sure you didn't cheat by using forums and such. Just an FYI!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 GeekSquaddd