5
UPDATE
    `universities`
SET
    `universities`.countryid = `countries`.id,
FROM
    `universities`
INNER JOIN
    `countries`
ON
    `universities`.country = `countries`.name

When I try to run the sql statements above via PhpMyAdmin, it would give syntax errors. I wrote the statements based on this answer.

1 Answer 1

12

This is the correct syntax in MySQL:

UPDATE universities u JOIN
       countries c
       ON u.country = c.name
    SET u.countryid = c.id;

In addition, I introduced table aliases (so the query is easier to write and to read) and removed an extraneous comma.

Sign up to request clarification or add additional context in comments.

2 Comments

Weird how this one works but many other with a lot of upvotes don't.
because the other one is using mariadb, meanwhile you are using mysql.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.