title: How UPDATE and check for duplicate key
body: <pre><code>        CREATE PROCEDURE update_logo_id_in_feeds(feed_id INT)
            BEGIN
              UPDATE feeds SET logo_id =
              (
                SELECT image_id
                FROM posts
                WHERE id =
                (
                   SELECT post_id 
                   FROM feed_posts 
                   WHERE priority=
                      (
                         SELECT MAX(feed_posts.priority)
                         FROM feed_posts
                         WHERE feed_posts.feed_id = feed_id
                      )
                   AND feed_posts.feed_id = feed_id
                )
              )
              WHERE feeds.id = feed_id;
            END 
  </code></pre>
  
  <p>I have such procedure. It call when new <code>post</code> add to <code>feed</code> (write in pivot table <code>feed_posts</code>) and set <code>logo_id</code>. I have 100 <code>feeds</code> and when I add one <code>post</code> to 100 <code>feeds</code> - all 100 <code>feeds</code> have same <code>logo_id</code>. How check when UPDATE if other <code>feeds</code> with such <code>logo_id</code> exists and don't update?</p>