Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update field value based on other table in mySql?
    primarykey
    data
    text
    <p>I have table <code>report_business_likes</code> with relevant fields:</p> <pre><code>id, facebook_id, created_at, some_info -- ----------- ----------- ---------- 1 123456789 '2013-12-23' blabla </code></pre> <p>I have other table named <code>businesses</code> with followed structure:</p> <pre><code>id, fb_id, data -- ----- ---- 33 123456789 xxx </code></pre> <p>I want to replace in <code>report_business_likes</code> field <code>facebook_id</code> with <code>id</code> from table <code>businesses</code>.</p> <p>In my case, the result should be:</p> <pre><code>id, facebook_id, created_at, some_info -- ----------- ----------- ---------- 1 33 '2013-12-23' blabla </code></pre> <p>As you can see I replaced <code>123456789</code> with <code>33</code>. </p> <p>How can I achieve that?</p> <p>I tried:</p> <pre><code>UPDATE `report_business_likes` SET facebook_id = BZ.id from (select id from `businesses` where fb_id = 123456789 ) as BZ, where facebook_id = 123456789 AND date(created_at) = '2013-12-23'; </code></pre> <p>But get syntax error:</p> <pre><code>[SQL] /*SELECT * FROM `report_business_likes` where facebook_id = 123456789 AND date(created_at) = '2013-12-23';*/ UPDATE `report_business_likes` SET facebook_id = BZ from (select id from `businesses` where fb_id = 123456789) as BZ, where facebook_id = 123456789AND date(created_at) = '2013-12-23'; [Err] 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 'from (select id from `businesses` where fb_id = 123456789) as BZ,' at line 3 </code></pre> <p>Please help,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload