سؤال

I try to copy a value from t2.f2 to t1.f1 namely, topics and posts tables of PHPbb3 forum. I have tried the following sql:

UPDATE t_topics SET
 topic_title = (SELECT t_posts.post_subject WHERE
  t_posts.post_id = t_topics.topic_first_post_id)
WHERE topic_id = 2;

I have got the following error:

MySQL said:

`#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE t_posts.post_id = t_topics.topic_first_post_id) WHERE topic_id = 2' at line 1

How could I achive this using sql?

هل كانت مفيدة؟

المحلول

You are missing a from clause:

UPDATE t_topics
    SET topic_title = (SELECT t_posts.post_subject
                       FROM t_posts
                       WHERE t_posts.post_id = t_topics.topic_first_post_id
                      )
    WHERE topic_id = 2;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top